Plot with 2 y-axes

classic Classic list List threaded Threaded
5 messages Options
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Plot with 2 y-axes

Hello fellow scilab-users,
I'm having a hard time creating a plot with two y-axes. This is what I tried so far:

// Visualization
clf();
// Channel 1
plot2d(1:10,1:10);
ax1=gca();
ax1.x_label.text="time";
ax1.y_label.text="ch1";
ax1.y_location="left";
ax1.foreground=5;
ax1.font_color=5; // red

// Channel 2
ax2=newaxes();
plot2d(1:10,5:-0.25:2.75);
ax2.y_label.text="ch2";
ax2.y_location="right";
ax1.foreground=2;
ax2.font_color=2; // blue

1.
First of all I'm missing my first plot. It seems to be erased by the 2nd one, although in the help it says "By default, successive plots are superposed."???

2.
For channel 1 I want to have all information in red, that is the line, y-axes, y-label but not x-axes. Same for ch2 but in blue. How do I achieve this?

3.
Is it possible to create a third y-axes like this:
https://i.stack.imgur.com/BYFr4.png
?

Many Thanks,
richard
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot with 2 y-axes

Hello,
There are 2 demos named plotyy() and plotyyy() that are examples that
you can edit and mimick, about this topic.
In addition, it was already dealt with in some quite recent threads in
this mailing list. You may have a look to the archives.
Regards
Samuel

Le 27/06/2017 à 00:51, Richard llom a écrit :

> Hello fellow scilab-users,
> I'm having a hard time creating a plot with two y-axes. This is what I tried
> so far:
>
> // Visualization
> clf();
> // Channel 1
> plot2d(1:10,1:10);
> ax1=gca();
> ax1.x_label.text="time";
> ax1.y_label.text="ch1";
> ax1.y_location="left";
> ax1.foreground=5;
> ax1.font_color=5; // red
>
> // Channel 2
> ax2=newaxes();
> plot2d(1:10,5:-0.25:2.75);
> ax2.y_label.text="ch2";
> ax2.y_location="right";
> ax1.foreground=2;
> ax2.font_color=2; // blue
>
> 1.
> First of all I'm missing my first plot. It seems to be erased by the 2nd
> one, although in the help it says "By default, successive plots are
> superposed."???
>
> 2.
> For channel 1 I want to have all information in red, that is the line,
> y-axes, y-label but not x-axes. Same for ch2 but in blue. How do I achieve
> this?
>
> 3.
> Is it possible to create a third y-axes like this:
> https://i.stack.imgur.com/BYFr4.png
> ?
>
> Many Thanks,
> richard
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Plot-with-2-y-axes-tp4036672.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot with 2 y-axes

Hello Samuel,
I couldn't find plotyy in the help, neither does plotyy() work for me:
"Undefined variable: plotyy"

I will take a look at the archives...

regards
richard


<quote author="Samuel GOUGEON">
Hello,
There are 2 demos named plotyy() and plotyyy() that are examples that
you can edit and mimick, about this topic.
In addition, it was already dealt with in some quite recent threads in
this mailing list. You may have a look to the archives.
Regards
Samuel

Le 27/06/2017 à 00:51, Richard llom a écrit :
> Hello fellow scilab-users,
> I'm having a hard time creating a plot with two y-axes. This is what I tried
> so far:
>
> // Visualization
> clf();
> // Channel 1
> plot2d(1:10,1:10);
> ax1=gca();
> ax1.x_label.text="time";
> ax1.y_label.text="ch1";
> ax1.y_location="left";
> ax1.foreground=5;
> ax1.font_color=5; // red
>
> // Channel 2
> ax2=newaxes();
> plot2d(1:10,5:-0.25:2.75);
> ax2.y_label.text="ch2";
> ax2.y_location="right";
> ax1.foreground=2;
> ax2.font_color=2; // blue
>
> 1.
> First of all I'm missing my first plot. It seems to be erased by the 2nd
> one, although in the help it says "By default, successive plots are
> superposed."???
>
> 2.
> For channel 1 I want to have all information in red, that is the line,
> y-axes, y-label but not x-axes. Same for ch2 but in blue. How do I achieve
> this?
>
> 3.
> Is it possible to create a third y-axes like this:
> https://i.stack.imgur.com/BYFr4.png
> ?
>
> Many Thanks,
> richard
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot with 2 y-axes

Le 27/06/2017 à 13:33, Richard llom a écrit :
> Hello Samuel,
> I couldn't find plotyy in the help, neither does plotyy() work for me:
> "Undefined variable: plotyy"

My fault: demos are not named plotyy() and plotyyy() but plotyy and plotyyy.
There are usages without dedicated functions. In the demos GUI:
--> demo_gui // go to the Graphics => 2D and 3D plot section

To get documentation on the archives, you may use for instance
--> uman plotyy|plotyyy @

after having installed uman:
--> atomsInstall uman


Samuel

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plot with 2 y-axes

Hi Samuel,
thanks I already figured it out with demo_gui and by searching the archive.

So for the record:
For my case I needed to create 3-axes:
1 for each extra y-axe and one "virtual" to get the x-axe in its own color scheme.

This is the code I ended up with:
timeaxis= [1:100];
// ==== Channel 1 ====
ch1_dye = color("red");  // Color for channel 1
// Plot channel 1 data
plot2d(timeaxis,log_data(:,2),style=ch1_dye);
// Axe configuration
ax1=gca();
ax1.y_label.text="ch1";                         // set Y-axe label
ax1.axes_visible(1) = "off";                        // hides X-axe
ax1.y_location="left";                              // Y-axe on the left
ax1.foreground = ch1_dye;                           // Axis and ticks color
ax1.font_color = ch1_dye;                           // sets color for ticks labels
ax1.y_label.font_foreground = ch1_dye;              // sets color for Y-label
ax1.tight_limits = "on";
ax1.tight_limits(2) = "off";                        // set tight limits off for y-axis for pretty tics labels

// ==== Channel 2 ====
ch2_dye = color("blue") // Color for channel 2
// Plot channel 2 data
ax2=newaxes();
plot2d(timeaxis,log_data(:,3),style=ch2_dye);
// Axe configuration
ax2.y_label.text = "ch2";                        // set Y-axe label
ax2.filled = "off";   // the background of the graphical area should be transparent, to leave the previous plot apparent
ax2.axes_visible(1) = "off";                         // hides X-axe
ax2.y_location = "right";                            // Y-axe on the right
ax2.foreground = ch2_dye;                            // Axis and ticks color
ax2.font_color = ch2_dye;                            // sets color for ticks labels
ax2.y_label.font_foreground = ch2_dye;               // sets color for Y-label

ax2.tight_limits="on";
//ax2.data_bounds(:,2) = [11;12.6];                  // set data bounds for Y-axe


// X-axe configuration

xax_dye = color("black"); // Color for X-axe
xax=newaxes();

xax.filled = "off";
xax.x_label.text="time";                          // set X-axe label
xax.axes_visible(1) = "on";                          // show X-axe
xax.axes_visible(2) = "off";                         // hides Y-axe
xax.foreground = xax_dye;                           // Axis and ticks color
xax.font_color = xax_dye;                           // sets color for ticks labels
xax.x_label.font_foreground = xax_dye;              // sets color for Y-label
xax.tight_limits="on";
xax.data_bounds = ax1.data_bounds;
Loading...