Change interval of color bar in contour scatter plot ?
조회 수: 21 (최근 30일)
이전 댓글 표시
Now I have my code plotting a scatter plot.
x = [1:0.1:10];
c = [10:-0.1:1];
y = zeros(1,91);
y = y - 1;
hold on
scatter(x,y,[],c,'s','Fill')
How can I change the contour and colorbar interval to be a certain value [1:2:10]
댓글 수: 5
채택된 답변
Adam Danz
2021년 2월 2일
> How can I change the color bar range for this code. I would like to have some how like Levels of [1:2:10]
This question is unclear and can be interpretted in several ways.
To change the color range use caxis().
To create a discrete colormap you've got several options.
If you only want n discrete colors you can use any of the colormap functions and specify the number of levels.
cmap = jet(n);
cmap = cool(n); % etc...
You can combine that with caxis to define when the discrete colors change. For example,
% Create colorbar that ranges 0:10 and changes
% colors at 0:2:10
cmap = jet(5);
set(gca, 'Colormap',cmap)
cb = colorbar();
caxis([0,10])
set(cb, 'Ticks', 0:2:10)
To create a discrete colormap that indicates ranges of x-values of a scatter plot, you need to set the color input to scatter defined by the discrete ranges of x-values.
% Create scatter data
x = 1:0.1:10;
y = zeros(1,91);
% Partition x values into bins to define color
edges = min(x):2:max(x)+1;
c = discretize(x, edges);
c = edges(c);
% Plot results
figure()
ax = axes();
scatter(ax, x,y,[],c,'s','Fill')
grid(ax, 'on')
ax.XTick = edges;
colormap(ax, jet(numel(edges)-1)); % set colormap
caxis(edges([1,end])) % set color range
cb = colorbar();
cb.Ticks = edges;
xlim([min(x)-1, max(x)+1])
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!