[Scilab-users] Scilab checkerboard plot (grayplot)

classic Classic list List threaded Threaded
7 messages Options
Ekin Akoglu Ekin Akoglu
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Scilab checkerboard plot (grayplot)

Dear all,

I am producing a checkerboard plot with Scilab and the plot seems
erroneously colored. The matrix I plot is attached as well as the
scripts to plot and the plot produced by Scilab.

The problem is that the data at matrix(1,3) and matrix(1,4) are equal,
however, on the plot produced by Scilab it is represented by different
colors (plants vs det. feeders and plants vs carnivores on the plot).
Let me remind you that the plot is transposed form of the matrix.

I would appreciate any help on the matter.

Kind regards,

Ekin


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

matrix.csv (428 bytes) Download Attachment
myMTIplot.sce (1K) Download Attachment
Scilab_mti.png (26K) Download Attachment
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? Scilab checkerboard plot (grayplot)

Le Vendredi, Avril 21, 2017 11:19 CEST, Ekin Akoglu <[hidden email]> a écrit:
 

> Dear all,
>
> I am producing a checkerboard plot with Scilab and the plot seems
> erroneously colored. The matrix I plot is attached as well as the
> scripts to plot and the plot produced by Scilab.
>
> The problem is that the data at matrix(1,3) and matrix(1,4) are equal,
> however, on the plot produced by Scilab it is represented by different
> colors (plants vs det. feeders and plants vs carnivores on the plot).
> Let me remind you that the plot is transposed form of the matrix.
>
> I would appreciate any help on the matter.
>
> Kind regards,
>
> Ekin
>
 
Hello,

The default behavior for grayplot is to paint a given pixel (a given square) with the color corresponding to its four corners.
See: "help data_mapping"
 You can either change the data_mapping after calling grayplot or use Matplot.
However, you'll have to rescale your data so that it ranges from 1 to nc where nc is the number of colors in your color_map.
See my modified function below.
Does it solve your problem?

Cheers,

Antoine

function myMTIplot(data)

[nrows ncols] = size(data);

data = [zeros(1,ncols); data; zeros(1,ncols)];
data = [zeros(1,nrows+2)' data zeros(1,nrows+2)'];

[nrows ncols] = size(data);

figure1 = scf();
a = newaxes();

colorbar(-1, 1);
grayplot(1:nrows, 1:ncols, data);

figure1.color_map = jetcolormap(32);

a.y_label.text = "Impacted Group";
a.y_label.font_size = 4;
a.x_label.text = "Impacting Group";
a.x_label.font_size = 4;
a.title.text = "Relative MTI";
a.title.font_size = 5;
a.font_size = 4;
a.data_bounds = [1, 6, 1, 6];

a.x_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
a.y_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);


//new version without interpolation
// we rescale the data so that is goes from 1 to 32
dat=(data-min(data))/(max(data)-min(data))*31+1;
figure2 = scf();
a = newaxes();

colorbar(-1, 1);
grayplot(1:nrows, 1:ncols, dat);
e=gce();e.data_mapping="direct";//no interpolation

figure2.color_map = jetcolormap(32);

a.y_label.text = "Impacted Group";
a.y_label.font_size = 4;
a.x_label.text = "Impacting Group";
a.x_label.font_size = 4;
a.title.text = "Relative MTI";
a.title.font_size = 5;
a.font_size = 4;
a.data_bounds = [1, 6, 1, 6];

a.x_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
a.y_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);


endfunction

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Ekin Akoglu Ekin Akoglu
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? Scilab checkerboard plot (grayplot)

Dear Antoine,

Thank you very much for the resolution. It solves my problem by
producing a graphically consistent plot. However, data-wise, the
colorbar does not match the plot unless I rescale it to (1,32). I want
to be able to infer the approximate value of the data from the colors.
However, thank you.

Kind regards,

Ekin


On 21/04/17 14:25, Antoine Monmayrant wrote:

> Le Vendredi, Avril 21, 2017 11:19 CEST, Ekin Akoglu <[hidden email]> a écrit:
>  
>> Dear all,
>>
>> I am producing a checkerboard plot with Scilab and the plot seems
>> erroneously colored. The matrix I plot is attached as well as the
>> scripts to plot and the plot produced by Scilab.
>>
>> The problem is that the data at matrix(1,3) and matrix(1,4) are equal,
>> however, on the plot produced by Scilab it is represented by different
>> colors (plants vs det. feeders and plants vs carnivores on the plot).
>> Let me remind you that the plot is transposed form of the matrix.
>>
>> I would appreciate any help on the matter.
>>
>> Kind regards,
>>
>> Ekin
>>
>  
> Hello,
>
> The default behavior for grayplot is to paint a given pixel (a given square) with the color corresponding to its four corners.
> See: "help data_mapping"
>   You can either change the data_mapping after calling grayplot or use Matplot.
> However, you'll have to rescale your data so that it ranges from 1 to nc where nc is the number of colors in your color_map.
> See my modified function below.
> Does it solve your problem?
>
> Cheers,
>
> Antoine
>
> function myMTIplot(data)
>
> [nrows ncols] = size(data);
>
> data = [zeros(1,ncols); data; zeros(1,ncols)];
> data = [zeros(1,nrows+2)' data zeros(1,nrows+2)'];
>
> [nrows ncols] = size(data);
>
> figure1 = scf();
> a = newaxes();
>
> colorbar(-1, 1);
> grayplot(1:nrows, 1:ncols, data);
>
> figure1.color_map = jetcolormap(32);
>
> a.y_label.text = "Impacted Group";
> a.y_label.font_size = 4;
> a.x_label.text = "Impacting Group";
> a.x_label.font_size = 4;
> a.title.text = "Relative MTI";
> a.title.font_size = 5;
> a.font_size = 4;
> a.data_bounds = [1, 6, 1, 6];
>
> a.x_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
> a.y_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
>
>
> //new version without interpolation
> // we rescale the data so that is goes from 1 to 32
> dat=(data-min(data))/(max(data)-min(data))*31+1;
> figure2 = scf();
> a = newaxes();
>
> colorbar(-1, 1);
> grayplot(1:nrows, 1:ncols, dat);
> e=gce();e.data_mapping="direct";//no interpolation
>
> figure2.color_map = jetcolormap(32);
>
> a.y_label.text = "Impacted Group";
> a.y_label.font_size = 4;
> a.x_label.text = "Impacting Group";
> a.x_label.font_size = 4;
> a.title.text = "Relative MTI";
> a.title.font_size = 5;
> a.font_size = 4;
> a.data_bounds = [1, 6, 1, 6];
>
> a.x_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
> a.y_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
>
>
> endfunction
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant Antoine Monmayrant
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? ?==?utf-8?q? ?= Scilab checkerboard plot (grayplot

Le Vendredi, Avril 21, 2017 14:27 CEST, Ekin Akoglu <[hidden email]> a écrit:
 
> Dear Antoine,
>
> Thank you very much for the resolution. It solves my problem by
> producing a graphically consistent plot. However, data-wise, the
> colorbar does not match the plot unless I rescale it to (1,32). I want
> to be able to infer the approximate value of the data from the colors.
> However, thank you.

Well, I don't use colorbar.
I usually replot a dummy rectangle that contains like this:
nc=32://number of colors
Rect=[linspace(min(data),max(data),nc);linspace(min(data),max(data),nc)]
I plot it in a second axis next to the one with the actual data and than set the ticks labels by hand to display the nc values.

Antoine

>
> Kind regards,
>
> Ekin
>
>
> On 21/04/17 14:25, Antoine Monmayrant wrote:
> > Le Vendredi, Avril 21, 2017 11:19 CEST, Ekin Akoglu <[hidden email]> a écrit:
> >  
> >> Dear all,
> >>
> >> I am producing a checkerboard plot with Scilab and the plot seems
> >> erroneously colored. The matrix I plot is attached as well as the
> >> scripts to plot and the plot produced by Scilab.
> >>
> >> The problem is that the data at matrix(1,3) and matrix(1,4) are equal,
> >> however, on the plot produced by Scilab it is represented by different
> >> colors (plants vs det. feeders and plants vs carnivores on the plot).
> >> Let me remind you that the plot is transposed form of the matrix.
> >>
> >> I would appreciate any help on the matter.
> >>
> >> Kind regards,
> >>
> >> Ekin
> >>
> >  
> > Hello,
> >
> > The default behavior for grayplot is to paint a given pixel (a given square) with the color corresponding to its four corners.
> > See: "help data_mapping"
> >   You can either change the data_mapping after calling grayplot or use Matplot.
> > However, you'll have to rescale your data so that it ranges from 1 to nc where nc is the number of colors in your color_map.
> > See my modified function below.
> > Does it solve your problem?
> >
> > Cheers,
> >
> > Antoine
> >
> > function myMTIplot(data)
> >
> > [nrows ncols] = size(data);
> >
> > data = [zeros(1,ncols); data; zeros(1,ncols)];
> > data = [zeros(1,nrows+2)' data zeros(1,nrows+2)'];
> >
> > [nrows ncols] = size(data);
> >
> > figure1 = scf();
> > a = newaxes();
> >
> > colorbar(-1, 1);
> > grayplot(1:nrows, 1:ncols, data);
> >
> > figure1.color_map = jetcolormap(32);
> >
> > a.y_label.text = "Impacted Group";
> > a.y_label.font_size = 4;
> > a.x_label.text = "Impacting Group";
> > a.x_label.font_size = 4;
> > a.title.text = "Relative MTI";
> > a.title.font_size = 5;
> > a.font_size = 4;
> > a.data_bounds = [1, 6, 1, 6];
> >
> > a.x_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
> > a.y_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
> >
> >
> > //new version without interpolation
> > // we rescale the data so that is goes from 1 to 32
> > dat=(data-min(data))/(max(data)-min(data))*31+1;
> > figure2 = scf();
> > a = newaxes();
> >
> > colorbar(-1, 1);
> > grayplot(1:nrows, 1:ncols, dat);
> > e=gce();e.data_mapping="direct";//no interpolation
> >
> > figure2.color_map = jetcolormap(32);
> >
> > a.y_label.text = "Impacted Group";
> > a.y_label.font_size = 4;
> > a.x_label.text = "Impacting Group";
> > a.x_label.font_size = 4;
> > a.title.text = "Relative MTI";
> > a.title.font_size = 5;
> > a.font_size = 4;
> > a.data_bounds = [1, 6, 1, 6];
> >
> > a.x_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
> > a.y_ticks = tlist(["ticks", "locations", "labels"], (1.5:1:5.5), ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
> >
> >
> > endfunction
> >
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.scilab.org/mailman/listinfo/users
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Scilab checkerboard plot (grayplot)

In reply to this post by Ekin Akoglu
Hello Ekin,

Le 21/04/2017 à 11:19, Ekin Akoglu a écrit :
Dear all,

I am producing a checkerboard plot with Scilab and the plot seems erroneously colored. The matrix I plot is attached as well as the scripts to plot and the plot produced by Scilab.

The problem is that the data at matrix(1,3) and matrix(1,4) are equal, however, on the plot produced by Scilab it is represented by different colors (plants vs det. feeders and plants vs carnivores on the plot). Let me remind you that the plot is transposed form of the matrix.

I would appreciate any help on the matter.

As Antoine wrote in his first answer, Matplot() must be used instead of grayplot().
The following simplified script can be used, yielding the following plot.

function myMTIplot(data)

// Rescaling data to a given range of indices
nc = 32; // number of colors
zmin = -1;
zmax = 1;
data2 = (data - zmin)/(zmax-zmin)*(nc-1) + zmax; 

// Plotting
clf
f = gcf();
f.color_map = jetcolormap(nc);
Matplot(data2)
a = gca();
colorbar(zmin, zmax);

a.sub_ticks(1) = 0;
xlabel("Impacting Group", "fontsize",4)
ylabel("Impacted Group", "fontsize", 4)
title("Relative MTI", "fontsize", 5);

[nrows, ncols] = size(data);
a.font_size = 3;
a.font_style = 8;
a.x_ticks = tlist(["ticks", "locations", "labels"], 1:ncols, ..
            ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
a.y_ticks = tlist(["ticks", "locations", "labels"], 1:nrows, ..
            ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
//
endfunction

M = csvRead("matrix.csv");
myMTIplot(M)


It correctly maps the given data matrix:

--> data
 data  =

   0.   0.4665757   0.2895315   0.2895315   0.4778269
   0.  -0.2942464  -0.1630711  -0.1630711  -0.3005833
   0.  -0.1058069  -0.4451125   0.5548875  -0.0842439
   0.   0.0774553  -0.3547458  -0.3547458   0.0636698
   0.   0.6032754   0.3743599   0.3743599  -0.3821769

HTH
Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Scilab checkerboard plot (grayplot)

There was a mistake in the mapping (+zmax instead of +1).
And may be about data transposition. The following shows
0 in the bottom row, as the plot you posted:

function myMTIplot(data)

// Rescaling data to a given range of indices
nc = 32; // number of colors
zmin = -1;
zmax = 1;
data2 = (data - zmin)/(zmax-zmin)*(nc-1) + 1; 
data2 = flipdim(data2',1);
// Plotting
clf
f = gcf();
f.color_map = jetcolormap(nc);
Matplot(data2)
a = gca();
colorbar(zmin, zmax);

xlabel("Impacting Group", "fontsize",4)
ylabel("Impacted Group", "fontsize", 4)
title("Relative MTI", "fontsize", 5);

[nrows, ncols] = size(data);
a.sub_ticks(1) = 0;
a.font_size = 3;
a.font_style = 8;
ticksText = tlist(["ticks", "locations", "labels"], 1:ncols, ..
            ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
a.x_ticks = ticksText;
a.y_ticks = ticksText;
endfunction

data = csvRead("matrix.csv");
myMTIplot(M)


--> flipdim(data',1)
 ans  =

   0.4778269  -0.3005833  -0.0842439   0.0636698  -0.3821769
   0.2895315  -0.1630711   0.5548875  -0.3547458   0.3743599
   0.2895315  -0.1630711  -0.4451125  -0.3547458   0.3743599
   0.4665757  -0.2942464  -0.1058069   0.0774553   0.6032754
   0.          0.          0.          0.          0.       


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Ekin Akoglu Ekin Akoglu
Reply | Threaded
Open this post in threaded view
|

Re: Scilab checkerboard plot (grayplot)

Dear Samuel,

Thank you for your help. This way it works as I wanted it to be. Matplot is the better way to go for my purposes. Thank you again.

It is a pity that the data need to be re-scaled before plotting, though. Otherwise, it gives a black plot with Matplot.

Best regards,

Ekin


On 22/04/17 12:15, Samuel Gougeon wrote:
There was a mistake in the mapping (+zmax instead of +1).
And may be about data transposition. The following shows
0 in the bottom row, as the plot you posted:

function myMTIplot(data)

// Rescaling data to a given range of indices
nc = 32; // number of colors
zmin = -1;
zmax = 1;
data2 = (data - zmin)/(zmax-zmin)*(nc-1) + 1; 
data2 = flipdim(data2',1);
// Plotting
clf
f = gcf();
f.color_map = jetcolormap(nc);
Matplot(data2)
a = gca();
colorbar(zmin, zmax);

xlabel("Impacting Group", "fontsize",4)
ylabel("Impacted Group", "fontsize", 4)
title("Relative MTI", "fontsize", 5);

[nrows, ncols] = size(data);
a.sub_ticks(1) = 0;
a.font_size = 3;
a.font_style = 8;
ticksText = tlist(["ticks", "locations", "labels"], 1:ncols, ..
            ["Plants", "Bacteria", "Det. Feeders", "Carnivores", "Detritus"]);
a.x_ticks = ticksText;
a.y_ticks = ticksText;
endfunction

data = csvRead("matrix.csv");
myMTIplot(M)


--> flipdim(data',1)
 ans  =

   0.4778269  -0.3005833  -0.0842439   0.0636698  -0.3821769
   0.2895315  -0.1630711   0.5548875  -0.3547458   0.3743599
   0.2895315  -0.1630711  -0.4451125  -0.3547458   0.3743599
   0.4665757  -0.2942464  -0.1058069   0.0774553   0.6032754
   0.          0.          0.          0.          0.       



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users