根据当前的色彩图选择一种颜色(Pick a color according to current colormap)

编程入门 行业动态 更新时间:2024-10-28 07:19:43
根据当前的色彩图选择一种颜色(Pick a color according to current colormap)

我的图包含许多半透明的等值面以显示密度。 我选择70:140范围的颜色:

vs=griddata(x,y,z,v,xs,ys,zs,'linear'); for i=70:5:140 p(i)=patch(isosurface(xs,ys,zs,vs,i)); isonormals(xs,ys,zs,vs,p(i)); rd=(i-70)/70; set(p(i),'facealpha',0.5); set(p(i),'FaceColor',[rd 0 1-rd],'EdgeColor','none'); % set colors end; alpha(0.3);

因此,这里的颜色从蓝色(密度= 70)到红色(密度= 140)不等。 如何从当前的colormap获取给定范围的颜色?

My graph contains a number of semi-transparent isosurfaces to visualize density. I choose the color for a range 70:140:

vs=griddata(x,y,z,v,xs,ys,zs,'linear'); for i=70:5:140 p(i)=patch(isosurface(xs,ys,zs,vs,i)); isonormals(xs,ys,zs,vs,p(i)); rd=(i-70)/70; set(p(i),'facealpha',0.5); set(p(i),'FaceColor',[rd 0 1-rd],'EdgeColor','none'); % set colors end; alpha(0.3);

So, here the colors vary from blue (density=70) to red (density=140). How to get a color for a given range from the current colormap?

最满意答案

文档说明了如何使用fix函数将值映射到colormap。

下面是您给出的范围的示例,其中可以使用cmap(index(i),:)访问颜色,范围为rng :

rng=70:5:140; cmap = colormap; m = size(cmap,1); index = fix((rng-min(rng))/range(rng)*m)+1; index(index<1) = 1; index(index>m) = m; % Plot example hold on; arrayfun(@(i) plot(rng(i),rng(i),'.', ... 'markersize',30,'color',cmap(index(i),:)),1:length(rng)); colorbar; hold off;

此示例输出以下图: matlab图的图像

The documentation explains here how the values are mapped to the colormap using the fix function.

Here is an example for the range you gave, where the color can be accessed using cmap(index(i),:) for an i in the range rng:

rng=70:5:140; cmap = colormap; m = size(cmap,1); index = fix((rng-min(rng))/range(rng)*m)+1; index(index<1) = 1; index(index>m) = m; % Plot example hold on; arrayfun(@(i) plot(rng(i),rng(i),'.', ... 'markersize',30,'color',cmap(index(i),:)),1:length(rng)); colorbar; hold off;

This example outputs the following plot: image of matlab plot

更多推荐

本文发布于:2023-07-14 13:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104792.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:彩图   颜色   的色   Pick   current

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!