[Scilab-users] grayplot - colorbar
Rafael Guerra
jrafaelbguerra at hotmail.com
Thu Nov 24 14:54:37 CET 2016
Hello Wolfgang,
The same message as Antoine, but in other words:
According to the help file, in Matplot1(M,rect), the values of int(M) are used as entries in the current colormap.
If the colormap indices run from 1 to Nc and M has values from z1 to z2, then in order to use the full color scale with Matplot1, we need to linearly transform M has indicated.
I.e., we need to find the straight line equation that maps the (z1,z2) range into (1,Nc).
Regarding the solution provided, please note that it works only for matrices with X and Y entries that are equally spaced.
With this proviso, you may add grids manually to Matplot1 as shown here below:
// START OF CODE
// plot a regular matrix with Matplot1
clf(); clear;
Nc= 128; // number of colors
dxp=0:5:10; // Points must be equispaced
dyp=0:10:20; // Points must be equispaced
x1=min(dxp);
y1=min(dyp);
M= [64 30 2; 4 5 6; 7 8 33] // M can have any real numbers
z1 = min(M);
z2 = max(M);
Mcol = 1+(Nc-1)*(M-z1)/(z2-z1); // scale data to colors indexes
ax = gca();//get current axes handle
ax.data_bounds = [min(dxp),min(dyp); max(dxp),max(dyp)]; //set the data_bounds
Matplot1(Mcol,[min(dxp),min(dyp), max(dxp),max(dyp)])
drawaxis(x=dxp,y=y1,dir='d',tics='v')
drawaxis(x=x1,y=dyp,dir='l',tics='v')
f = gcf();
f.color_map = jetcolormap(Nc);
colorbar(z1,z2,[1 Nc]);
Nx= length(dxp);
Ny= length(dyp);
for i=1:Nx-1
yi= i*(dyp($)-dyp(1))/Ny;
xpoly([dxp(1);dxp($)],[yi;yi]);
e=gce();
e.thickness = 3;
e.line_style=8;
e.foreground= color("black");
end
for i=1:Ny-1
xi= i*(dxp($)-dxp(1))/Nx;
xpoly([xi;xi],[dyp(1);dyp($)]);
e=gce();
e.thickness = 3;
e.line_style=8;
e.foreground= color("black");
end
// END OF CODE
As for the default axes labels, as xlabel, they are placed poorly in this case and you will need to do it manually.
Regards,
Rafael
More information about the users
mailing list