Scilab: same colormap in contourf

对着背影说爱祢 提交于 2019-12-23 05:35:13

问题


When the following program is run, It becomes the same figure. I want the same color-coding.

x=-5:0.1:5;
y=-5:0.1:5;
[X,Y]=meshgrid(x,y);
z1=X.^2+Y.^2-25;
z2=X.^2+Y.^2-50;
clf();
f=gcf();
f.color_map=jetcolormap(32);
subplot(1,2,1);
contourf([],[],z1,32);
subplot(1,2,2);
contourf([],[],z2,32);

回答1:


I don't know how to do it with contourf, but if you can use surf instead, I have a suggestion.

Please note, that surf generates a 3D plot, but you can rotate it to seem as a 2D plot. And as a surface it has the cdata_mapping property, which can be changed from scaled to direct and scale the color matrix (which defines the color of each facet) according to the actual range used:

x=-5:0.1:5;
y=-5:0.1:5;
[X,Y]=meshgrid(x,y);
z1=X.^2+Y.^2-25;
z2=X.^2+Y.^2-50;

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

clf();
f=gcf();
f.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'
h.color_mode=-1;  //don't draw mesh
a=gca();
a.view="2d";  //2D view instead of 3D
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'
h.color_mode=-1;  //don't draw mesh
a=gca();
a.view="2d";  //2D view instead of 3D
colorbar(Zmin,Zmax);

Is this a solution for you, or you have to use contourf in any circumstances?



来源:https://stackoverflow.com/questions/32880074/scilab-same-colormap-in-contourf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!