<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Thanks for sharing it.</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">I've a suggestion I commonly use for such plots (I'm speaking in a general way): the color of the dedicated ordinate axis is the same than the curve in order to immediatly know what are the units and where to look to ...</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">... just my point of view</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Paul</div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div>
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Le 2017-03-28 09:51, mathias_magdowski a écrit :
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">I have extended the given example in a way that the left and right y axis get<br /> some kind of intelligent equal scaling, so that a joined grid for both axes<br /> would fit. If one of the axes includes the value of y = 0, both axes will<br /> also share the same "base line".<br /> <br /> Here is the function:<br /> <br /> // Function for plotting a diagram with two y axes<br /> // Input:<br /> // x - x values -> vector<br /> // y1 - y values for the for the left y axis -> vector<br /> // y2 - y values for the right y axis -> vector<br /> // Output:<br /> // a1, a2 - axes -> handle<br /> function [a1,a2]=plotyy(x,y1,y2)<br /> // example for a diagram with two y axes<br /> // see:<br /> <a href="https://commons.wikimedia.org/wiki/File:Trace_ln_sqrt_1_2_deux_echelles_scilab.svg" target="_blank" rel="noreferrer">https://commons.wikimedia.org/wiki/File:Trace_ln_sqrt_1_2_deux_echelles_scilab.svg</a><br /> // and: <br /> <a href="http://mailinglists.scilab.org/Scilab-users-Plots-on-second-Y-axis-td4025895.html" target="_blank" rel="noreferrer">http://mailinglists.scilab.org/Scilab-users-Plots-on-second-Y-axis-td4025895.html</a><br /> // generation of the right y axis<br /> a1=newaxes();<br /> a1.tight_limits=["on","off","off"];<br /> // plot of the first function<br /> plot(x,y1);<br /> // generation of the right y axis<br /> a2=newaxes();<br /> // no background for this plot<br /> a2.filled="off";<br /> // hide second x axis<br /> a2.axes_visible(1)="off";<br /> a2.y_location = "right";<br /> a2.tight_limits = "on";<br /> // plot of the second function<br /> plot(x,y2,"r");<br /> // set font size<br /> a1.font_size=3;<br /> a2.font_size=3;<br /> // delete tick marks of the first x axis<br /> a1.x_ticks=tlist(["ticks","locations","labels"],[],[])<br /> // add a grid<br /> a1.grid=[1,1];<br /> a2.grid=[1,1];<br /> // end of plotting<br /> // algorithm to equally scale the axes<br /> // minimum of the first function -> scalar<br /> y1min=min(y1);<br /> // maximum of the first function -> scalar<br /> y1max=max(y1);<br /> // minimum of the second function -> scalar<br /> y2min=min(y2);<br /> // maximum of the second function -> scalar<br /> y2max=max(y2);<br /> // divider for the first function -> scalar<br /> division1=find_division(y1min,y1max);<br /> // divider for the second function -> scalar<br /> division2=find_division(y2min,y2max);<br /> // lower axis left y axis the first function (normalized) -> scalar<br /> y1axismin=floor(y1min/division1)<br /> // upper axis left y axis the first function (normalized) -> scalar<br /> y1axismax=ceil(y1max/division1)<br /> // lower axis left y axis the second function (normalized) -> scalar<br /> y2axismin=floor(y2min/division2)<br /> // upper axis left y axis the second function (normalized) -> scalar<br /> y2axismax=ceil(y2max/division2)<br /> // distinction of cases<br /> if y1axismin*y1axismax>0 & y2axismin*y2axismax>0 then<br /> // both axes don't go over the value of zero<br /> // preset variable<br /> addupper=1;<br /> // start a loop, until both axes have the same number of dividers<br /> while y1axismax-y1axismin>y2axismax-y2axismin<br /> // left y axis has more dividers than the right y axis<br /> if addupper==1 & y2axismax~=-1<br /> // move the upper limit of the right y axis up<br /> y2axismax=y2axismax+1;<br /> end<br /> if addupper==-1 & y2axismin~=1<br /> // move the lower limit of the right y axis down<br /> y2axismin=y2axismin+1;<br /> end<br /> // toggle variable<br /> addupper=adduper*(-1);<br /> end<br /> // preset variable<br /> addupper=1;<br /> // start a loop, until both axes have the same number of dividers<br /> while y1axismax-y1axismin<y2axismax-y2axismin<br /> // left y axis hat weniger optimum rounded divider als right y<br /> axis<br /> if addupper==1 & y1axismax~=-1<br /> // move the upper limit of the left y axis up<br /> y1axismax=y1axismax+1;<br /> end<br /> if addupper==-1 & y1axismin~=1<br /> // move the lower limit of the left y axis down<br /> y1axismin=y1axismin+1;<br /> end<br /> // toggle variable<br /> addupper=adduper*(-1);<br /> end<br /> // rescale axes<br /> // lower limit of the left y axis<br /> a1.data_bounds(1,2)=y1axismin*division1;<br /> // lower limit of the left y axis<br /> a1.data_bounds(2,2)=y1axismax*division1;<br /> // lower limit of the left y axis<br /> a2.data_bounds(1,2)=y2axismin*division2;<br /> // lower limit of the left y axis<br /> a2.data_bounds(2,2)=y2axismax*division2;<br /> else<br /> // at least one of the axes goes over zero, or starts or ends at<br /> zero<br /> // find joint lower limit of both axes -> scalar<br /> ymin=min(y1axismin,y2axismin);<br /> // find joint upper limit of both axes -> scalar<br /> ymax=max(y1axismax,y2axismax);<br /> // rescale axes<br /> // lower limit of the left y axis<br /> a1.data_bounds(1,2)=ymin*division1;<br /> // lower limit of the left y axis<br /> a1.data_bounds(2,2)=ymax*division1;<br /> // lower limit of the left y axis<br /> a2.data_bounds(1,2)=ymin*division2;<br /> // lower limit of the left y axis<br /> a2.data_bounds(2,2)=ymax*division2;<br /> end<br /> endfunction<br /> <br /> // Function to find a good division for the grid of a diagram<br /> // Input:<br /> // axismin: minimum of the data to display -> scalar<br /> // axismax: maximum of the data to display -> scalar<br /> // Output:<br /> // division: optimum rounded divider to divide the axis into 5 to 10 parts<br /> function division=find_division(axismin,axismax)<br /> // distance between maximum and minimum -> scalar<br /> distance=axismax-axismin;<br /> // preset exponent -> scalar<br /> exponent=0;<br /> // loop, until the distance is between 1 and 10<br /> while 1<br /> if distance>10 then<br /> // decrease distance -> scalar<br /> distance=distance/10;<br /> // increase exponent -> scalar<br /> exponent=exponent+1;<br /> elseif distance<1 then<br /> // increase distance -> scalar<br /> distance=distance*10;<br /> // decrease exponent -> scalar<br /> exponent=exponent-1;<br /> else<br /> // exit loop<br /> break;<br /> end<br /> end<br /> // distinction of cases, so that there will be 5 to 10 dividers at the<br /> end<br /> if distance==1 then<br /> // optimum rounded divider -> scalar<br /> division=0.1;<br /> elseif distance<=2 then<br /> // optimum rounded divider -> scalar<br /> division=0.2;<br /> elseif distance<=5 then<br /> // optimum rounded divider -> scalar<br /> division=0.5;<br /> else<br /> // optimum rounded divider -> scalar<br /> division=1;<br /> end<br /> // adjust the scaling -> scalar<br /> division=division*10^exponent;<br /> endfunction<br /> <br /> <br /> <br /> --<br /> View this message in context:<br /> <a href="http://mailinglists.scilab.org/Scilab-users-Plots-on-second-Y-axis-tp4025895p4036055.html" target="_blank" rel="noreferrer">http://mailinglists.scilab.org/Scilab-users-Plots-on-second-Y-axis-tp4025895p4036055.html</a><br /> Sent from the Scilab users - Mailing Lists Archives mailing list<br /> archive at Nabble.com.<br /> _______________________________________________<br /> users mailing list<br /> <a href="mailto:users@lists.scilab.org">users@lists.scilab.org</a><br /> <a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank" rel="noreferrer">http://lists.scilab.org/mailman/listinfo/users</a></blockquote>
</div>
</body></html>