- Vector of colormap indices — A vector of numeric values that is the same length as the x and y vectors.
How to make colororder function working in scatter plot
5 次查看(过去 30 天)
显示 更早的评论
I am trying to use the colororder function in my scatter plot, but somehow it is not working and couldn't able to understand why.
% Data file is attached
figure(1);
newcolors=["#FF0000" "#00FF00" "#0000FF" "#00FFFF" "#FF00FF"];
colororder(newcolors);
s=scatter(lon,lat,36,index(1,:),"filled");
ax = gca;
ax.FontSize = 12;
xticks([66 74 82 90 98]);
xticklabels([66 74 82 90 98]);
ylim([6.5 39.5]);
yticks([8 14 20 26 32 38]);
ylabel(ax,"Latitude","FontSize",20);
xlabel(ax,"Latitude","FontSize",20);
0 个评论
采纳的回答
Voss
2025-3-2
编辑:Voss
2025-3-2
When you specify a vector of values for the colors (index(1,:) in this case), those values are interpreted as indices into the axes' Colormap, as explained here.
Therefore you need to set the axes Colormap rather than its ColorOrder. See below for one way to do that.
load Data
% Data file is attached
figure(1);
newcolors=["#FF0000" "#00FF00" "#0000FF" "#00FFFF" "#FF00FF"];
s=scatter(lon,lat,36,index(1,:),"filled");
ax = gca;
ax.Colormap = hex2rgb(newcolors);
ax.FontSize = 12;
xticks([66 74 82 90 98]);
xticklabels([66 74 82 90 98]);
ylim([6.5 39.5]);
yticks([8 14 20 26 32 38]);
ylabel(ax,"Latitude","FontSize",20);
xlabel(ax,"Latitude","FontSize",20);
When no colors are specified in the scatter() call, then the resulting scatter objects are colored according to the axes ColorOrder, with one color per scatter object (not necessarily one color per scatter point). [The examples in the scatter documentation showing the effect of changing the axes ColorOrder create multiple scatter objects, letting the scatter function determine their colors automatically from the axes ColorOrder.] That is not relevant to this case, since your scatter object needs to have multiple colors in it, in order for its points to be colored according to index(1,:) and newcolors.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
