[Scilab-users] Plot w. part of background in a different color

classic Classic list List threaded Threaded
4 messages Options
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Plot w. part of background in a different color

Hi there

A friend of mine uses Python matplotlib for some graphs and I'd like to
generate similar graphs in Scilab.

I've attached an example of such a plot.

What I'd like to replicate is part of the background shaded in green and
red.

I think the function in Python matplotlib is something like:

axvspan (xmin,xmax,ymin=0,ymax=1,hold=None, **kwargs)

The kwargs are named arguments, for example: facecolor='g',alpha=0.1

Examples here:
http://matplotlib.org/examples/pylab_examples/axhspan_demo.html

http://physicalmodelingwithpython.blogspot.no/2015/08/function-arguments-args-and-kwargs.html

How would I do similar stuff in Scilab? (Searching for vspan and hspan
didn't give any hits).

Best regards,
Claus

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

FD.c0.png (58K) Download Attachment
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Plot w. part of background in a different color

Hello Clauss,

Here is an example that you may customize:
x = linspace(0,10,100);
clf
drawlater
plot(x,sin(x))
xgrid(color("grey70"))
xfpolys([2 5 5 2 ; 7 8.5 8.5 7]',[-1 -1 1 1; -1 -1 1 1]',..
         [color("scilabpink") color("bisque")])
r = gca();
r.grid_position = "foreground";
r = r.children(1).children;
r.line_mode="off";
r(1).data(:,3)=-1;
r(2).data(:,3)=-1;
drawnow



HTH
Samuel

Le 04/03/2016 21:54, Claus Futtrup a écrit :
Hi there

A friend of mine uses Python matplotlib for some graphs and I'd like to generate similar graphs in Scilab.

I've attached an example of such a plot.

What I'd like to replicate is part of the background shaded in green and red.

I think the function in Python matplotlib is something like:

axvspan (xmin,xmax,ymin=0,ymax=1,hold=None, **kwargs)

The kwargs are named arguments, for example: facecolor='g',alpha=0.1

Examples here: http://matplotlib.org/examples/pylab_examples/axhspan_demo.html

http://physicalmodelingwithpython.blogspot.no/2015/08/function-arguments-args-and-kwargs.html

How would I do similar stuff in Scilab? (Searching for vspan and hspan didn't give any hits).

Best regards,
Claus


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

Re: Plot w. part of background in a different color

Hi there

Thank you Samuel, it was very helpful. I have a few follow-up questions

I do a double-log plot.

a
.log_flags = "lln"; // double-log plot
a.auto_scale = "off";

When I plot the polygons, then I use data_bounds now, but on the y-axis, the axis goes a bit further_

ymin
= a.data_bounds(3);
ymax = a.data_bounds(4); // if ymax = 20.1 ... then plot goes to 30 !
xfpolys([f(im1) f(im2) f(im2) f(im1) ; f(ie1) f(ie2) f(ie2) f(ie1)]', ..
            [ymin ymin ymax ymax; ymin ymin ymax ymax]', [color("bisque") color("scilabpink")]);

Is there a way to determine what is the upper limit for the y-axis? ... a.axes_bounds doesn't seem to be helpful in any way (or am I looking in the wrong place?).

a
.grid_position = "foreground"; // put grid in the foreground - in front of the polygons
a = a.children(1).children; // what does this do?

As the comment says - what does children(1).children do?

a
.line_mode="off"; // don't 'box/frame' the polygons (background squares)
a(1).data(:,3)=-1; // data(:,1) = xaxis data, data(:,2) = yaxis data
a(2).data(:,3)=-1; // data(:,3) = ???

We set data(:,3) = -1 ... I can see the content in ,2 and ,1 ... but what's in the third column? and why do we set it = -1 ?? ... I see a(1) = first polygon (a 'box' in our case) and that a(2) = second polygon-box. So is the third  column = z-axis data? ... Why do we need to make sure z-axis data are negative = -1 ??

Best regards,
Claus

On 04-03-2016 23:06, Samuel Gougeon wrote:
Hello Clauss,

Here is an example that you may customize:
x = linspace(0,10,100);
clf
drawlater
plot(x,sin(x))
xgrid(color("grey70"))
xfpolys([2 5 5 2 ; 7 8.5 8.5 7]',[-1 -1 1 1; -1 -1 1 1]',..
         [color("scilabpink") color("bisque")])
r = gca();
r.grid_position = "foreground";
r = r.children(1).children;
r.line_mode="off";
r(1).data(:,3)=-1;
r(2).data(:,3)=-1;
drawnow



HTH
Samuel

Le 04/03/2016 21:54, Claus Futtrup a écrit :
Hi there

A friend of mine uses Python matplotlib for some graphs and I'd like to generate similar graphs in Scilab.

I've attached an example of such a plot.

What I'd like to replicate is part of the background shaded in green and red.

I think the function in Python matplotlib is something like:

axvspan (xmin,xmax,ymin=0,ymax=1,hold=None, **kwargs)

The kwargs are named arguments, for example: facecolor='g',alpha=0.1

Examples here: http://matplotlib.org/examples/pylab_examples/axhspan_demo.html

http://physicalmodelingwithpython.blogspot.no/2015/08/function-arguments-args-and-kwargs.html

How would I do similar stuff in Scilab? (Searching for vspan and hspan didn't give any hits).

Best regards,
Claus



_______________________________________________
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: Plot w. part of background in a different color

Hi Claus,

Le 05/03/2016 09:39, Claus Futtrup a écrit :
Hi there

Thank you Samuel, it was very helpful. I have a few follow-up questions

I do a double-log plot.

a
.log_flags = "lln"; // double-log plot
a.auto_scale = "off";

When I plot the polygons, then I use data_bounds now, but on the y-axis, the axis goes a bit further_

ymin
= a.data_bounds(3);
ymax = a.data_bounds(4); // if ymax = 20.1 ... then plot goes to 30 !
xfpolys([f(im1) f(im2) f(im2) f(im1) ; f(ie1) f(ie2) f(ie2) f(ie1)]', ..
            [ymin ymin ymax ymax; ymin ymin ymax ymax]', [color("bisque") color("scilabpink")]);

Is there a way to determine what is the upper limit for the y-axis? ... a.axes_bounds doesn't seem to be helpful in any way (or am I looking in the wrong place?).
.
.data_bounds are reliable only if gca().tight_limits="on". Otherwise, AFAIK, there is presently no way to get the true bounds of the displayed axes. This has been reported.


a
.grid_position = "foreground"; // put grid in the foreground - in front of the polygons
a = a.children(1).children; // what does this do?

As the comment says - what does children(1).children do?
.
It is a vector of handles. It points to the set of background rectangles generated with xfpolys(). It makes "lighter" forthcoming operations on the rectangles.

a
.line_mode="off"; // don't 'box/frame' the polygons (background squares)
a(1).data(:,3)=-1; // data(:,1) = xaxis data, data(:,2) = yaxis data
a(2).data(:,3)=-1; // data(:,3) = ???

We set data(:,3) = -1 ... I can see the content in ,2 and ,1 ... but what's in the third column?
Z. It is not assigned by default when the axes is in 2D .view. Nevertheless, Z can be set to manage overlays.
This is possible with polylines, but not with the rect graphical type (as plotted with fxrects()).

and why do we set it = -1 ?? ... I see a(1) = first polygon (a 'box' in our case) and that a(2) = second polygon-box. So is the third  column = z-axis data? ... Why do we need to make sure z-axis data are negative = -1 ??
.
Change the value, and you will see why. No worry, it won't explode :) I tried 0, but when it is on the foreground, the grid looks to be set between 0 and -1. You can play with .grid_position and the Z value (i did it), you will see. The Z of the grid can't be tuned accurately. They can have only 2 predefined positions. It is not very efficient. A .grid_z attribute would have been better (and clearer)  than .grid_position. It could come just by mimicking some other softwares. This is too often the very ambition of Scilab : just mimicking others.

Since Scilab does not managed transparency (alpha channel), there will be a problem if you draw crossed rectangles. The common part will have the color of the highest-z rectangle.
It was formerly possible to tuned the rendering mode -- setting the new pixel color according to the current color of the pixel -- but
1) it applied to the whole figure :
https://help.scilab.org/docs/5.5.2/en_US/pixel_drawing_mode.html
2) it is out-of-work since Scilab > 5.3.3  : http://bugzilla.scilab.org/12017

Here is what was possible with 2 octogons filled with bisque and powderblue predefined colors,
and the regression brought by Scilab 5.4.0, still unfixed.
 

Samuel



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