Scilab:两个子图的相同颜色条(Scilab : Same colorbar for two subplots)

编程入门 行业动态 更新时间:2024-10-28 12:21:55
Scilab:两个子图的相同颜色条(Scilab : Same colorbar for two subplots)

我有两个变量(z1和z2),它们是x和y的函数。 我想使用相同的颜色条在两个子图中绘制它们。 这两个变量具有不同的最小值和最大值。 所以,我想将颜色条定义为(z1,z2)的最小值,并以(z1,z2)的最大值结束。 因此我使用:

figure=scf(); figure.color_map=jetcolormap(32); subplot1=subplot(121); surf(x,y,z1); subplot2=subplot(122); surf(x,y,z2); colorbar(min(min(min(z1)),min(min(z2))),max(max(max(z1)),max(max(z2))));

但是这样做,我使用他们自己的颜色条得到两个图,分别对应于它们的最小值和最大值。 我知道我们可以在Matlab上使用属性作为caxis和climb来获得这种行为。 但我不知道Scilab相当于这些属性。

如果用Scilab的基本版本无法做到这一点,请你告诉我一些Scilab允许这样做的图书馆。

谢谢你的帮助。

I have two variables (z1 and z2) which are function of x and y. I would like to plot them in two subplot using the same colorbar. These two variables have different min and max value. So, I would like define the colorbar as begining by the min of (z1,z2) and finishing by the max of (z1,z2). Therefore I use:

figure=scf(); figure.color_map=jetcolormap(32); subplot1=subplot(121); surf(x,y,z1); subplot2=subplot(122); surf(x,y,z2); colorbar(min(min(min(z1)),min(min(z2))),max(max(max(z1)),max(max(z2))));

But doing like this, I get two graph using theirs own colorbar which correspond respectively to their min and max. I know that we can get this behaviour on Matlab using properties as caxis and clim. But I don't know the equivalent of these properties for Scilab.

If it's not possible to do this with the basic version of Scilab, could you please advise to me some libraries Scilab permitting to do this.

Thanks for your help.

最满意答案

您可以尝试将cdata_mapping从“scaled”更改为“direct”,并根据实际使用的范围缩放颜色矩阵(定义每个facet的颜色):

x=[0:0.3:2*%pi]; //example data [X,Y]=ndgrid(x,x); Z1=sin(x')*cos(x); //first data set Z2=Z1./2; //second dataset is half in amplitude Zmin=min(min(Z1),min(Z2)); //Absolut minimum of all data sets Zmax=max(max(Z1),max(Z2)); //Absolut maximum of all data sets nc=100; //number of colors in colormap tabl=scf(); tabl.color_map=jetcolormap(nc); subplot(1,2,1); surf(X,Y,Z1); h=gce(); cm=h.data.color; //color matrix h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1; //scale color matrix & convert to color number h.cdata_mapping="direct"; //change color mapping from 'scaled' to 'direct' colorbar(Zmin,Zmax); subplot(1,2,2); surf(X,Y,Z2); h=gce(); cm=h.data.color; //color matrix h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1; //scale color matrix & convert to color number h.cdata_mapping="direct"; //change color mapping from 'scaled' to 'direct' colorbar(Zmin,Zmax);

You may try to change the cdata_mapping from 'scaled' to 'direct' and scale the color matrix (which defines the color of each facet) according to the actual range used:

x=[0:0.3:2*%pi]; //example data [X,Y]=ndgrid(x,x); Z1=sin(x')*cos(x); //first data set Z2=Z1./2; //second dataset is half in amplitude Zmin=min(min(Z1),min(Z2)); //Absolut minimum of all data sets Zmax=max(max(Z1),max(Z2)); //Absolut maximum of all data sets nc=100; //number of colors in colormap tabl=scf(); tabl.color_map=jetcolormap(nc); subplot(1,2,1); surf(X,Y,Z1); h=gce(); cm=h.data.color; //color matrix h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1; //scale color matrix & convert to color number h.cdata_mapping="direct"; //change color mapping from 'scaled' to 'direct' colorbar(Zmin,Zmax); subplot(1,2,2); surf(X,Y,Z2); h=gce(); cm=h.data.color; //color matrix h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1; //scale color matrix & convert to color number h.cdata_mapping="direct"; //change color mapping from 'scaled' to 'direct' colorbar(Zmin,Zmax);

更多推荐

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

发布评论

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

>www.elefans.com

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