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!