<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><br>Very ingenious matrix trick, I loved it<br><br><div><hr id="stopSpelling">Date: Wed, 7 Oct 2015 11:47:49 +0200<br>From: Serge.Steer@inria.fr<br>To: users@lists.scilab.org<br>Subject: Re: [Scilab-users] How to produce a filled staircase plot<br><br>
  
    
  
  
    <div class="ecxmoz-cite-prefix">Under Scilab-5.5.2 xfpoly rescale the
      graph automatically as plot does<br>
      <br>
      A little more simple (efficient?) code:<br>
      <br>
      t = [ 0  2  5 10 12 17 20 30 35 45 60]'*0.1;<br>
      N = [20 18 15 14 12  9  6  4  3  2  1]';<br>
      <br>
      t2=matrix([t' t($); t' t($)],-1,1);<br>
      N2=matrix([0 N'; N' 0],-1,1)<br>
      <br>
      clf;<br>
      xfpoly(t2,N2);<br>
      h = gce();<br>
      h.line_mode = "off";<br>
      h.background = color('gray');<br>
      plot(t2(2:$-1),N2(2:$-1),'black',
      t2(2:$-1),21*exp(-t2(2:$-1)/2),'red');<br>
       <br>
      <br>
      <br>
      <br>
       <br>
      Le 07/10/2015 09:58, Antoine Monmayrant a écrit :<br>
    </div>
    <blockquote cite="mid:5614D091.9020103@laas.fr">
      
      <div class="ecxmoz-cite-prefix">Le 10/07/2015 09:41 AM, Yann DEBRAY a
        écrit :<br>
      </div>
      <blockquote cite="mid:5614CCA1.8000301@scilab-enterprises.com">
        
        Hello Raphael,<br>
        <br>
        Nice plot, but sadly it doesn't rescale.<br>
        Do you have an idea how to make it fit the axes, to rescale
        automatically?<br>
      </blockquote>
      <br>
      You can calculate your data_bounds and set them after plotting.<br>
      Alernatively, use my method that does not rely on xfpoly, but on
      plot that rescales automatically:<br>
      <br>
      //I want to staircase plot N(Decay_times)<br>
          N=[N2,N2-cumsum(ones(Decay_times))+1];<br>
          Np1=[N2-cumsum(ones(Decay_times))+1,0];<br>
          Ns=matrix([N;Np1],2*prod(size(N)));<br>
          Decay_times=[0,Decay_times];<br>
          <br>
         
      D_t=matrix([Decay_times;Decay_times],2*prod(size(Decay_times)));<br>
      //in the end, I plot Ns(D_t)<br>
          Ns=[0;Ns];<br>
          D_t=[0;D_t];<br>
      //plot it<br>
          plot(D_t,Ns, 'k-');<br>
      //fill the bacground<br>
          e=gce();<br>
          e.children.polyline_style=1;<br>
          e.children.closed='off';<br>
          e.children.background=color('gray');<br>
      <br>
      <blockquote cite="mid:5614CCA1.8000301@scilab-enterprises.com"> <br>
        Yann<br>
        <br>
        <div class="ecxmoz-cite-prefix">Le 07/10/2015 00:17, Rafael Guera a
          écrit :<br>
        </div>
        <blockquote cite="mid:BLU436-SMTP20052F19EA9E25D4BF40C18CC370@phx.gbl">
          <pre>Hello Antoine,
 
An attempt below, not particularly clean but I hope not too dirty either:
 
//INPUT
t = [ 0  2  5 10 12 17 20 30 35 45 60]'*0.1;
N = [20 18 15 14 12  9  6  4  3  2  1]';
 
t2=[];N2=[];
ns= length(t);
t2(1:2:2*ns) = t;  
t2(2:2:2*ns) = [t(2:$)-%eps; t($)];
N2(1:2:2*ns-1) = N;
N2(2:2:2*ns) = N;
clf;
xfpoly([t2(1)-%eps;t2;t2($)+%eps],[0;N2;0]);
h = gce();
h.line_mode = "off";
h.background = color('gray');
plot(t2,N2,'black', t2,21*exp(-t2/2),'red');
 
 
Regards,
 
Rafael
 
-----Original Message-----
From: users [<a class="ecxmoz-txt-link-freetext" href="mailto:users-bounces@lists.scilab.org">mailto:users-bounces@lists.scilab.org</a>] On Behalf Of Antoine Monmayrant
Sent: Tuesday, October 06, 2015 10:57 AM
To: Users mailing list for Scilab <a class="ecxmoz-txt-link-rfc2396E" href="mailto:users@lists.scilab.org"><users@lists.scilab.org></a>
Subject: Re: [Scilab-users] How to produce a filled staircase plot
 
Thank you Serge for this solution, but it does not work for me: the "bars" in my case are not regular.
I am simulating an exponential random decay: starting from a number N0, my population decreases by jumps of N0->N0-1 that occur at random times, following an exponential law (see the attached plot).
For the moment, I just build my polygon by hand, but it adds quite a lot of "noise" on top of the code that I intent to show to my students.
I was hoping for a cleaner solution.
 
Thanks anyway,
 
Cheers,
 
Antoine
 
Le Mardi 6 Octobre 2015 11:42 CEST, Serge Steer < <a class="ecxmoz-txt-link-rfc2396E" href="mailto:Serge.Steer@inria.fr"><mailto:Serge.Steer@inria.fr></a> <a class="ecxmoz-txt-link-abbreviated" href="mailto:Serge.Steer@inria.fr">Serge.Steer@inria.fr</a>> a écrit: 
 
</pre>
          <blockquote>
            <pre>Le 06/10/2015 00:01, Antoine Monmayrant a écrit :
</pre>
            <blockquote>
              <pre>Hi everyone,

I'm trying to do a filled staircase plot (ie a staircase where the area between the staircase and the x axis is filled with a solid color).
Is there a given combination of polyline_style and fill_mode, etc ... that can do this?
Or should I resort to building a polygon by hand?

Thanks in advance,

Antoine

_______________________________________________
users mailing list
 <a class="ecxmoz-txt-link-rfc2396E" href="mailto:users@lists.scilab.org"><mailto:users@lists.scilab.org></a> <a class="ecxmoz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
 <a class="ecxmoz-txt-link-rfc2396E" href="http://lists.scilab.org/mailman/listinfo/users" target="_blank"><http://lists.scilab.org/mailman/listinfo/users></a> <a class="ecxmoz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/mailman/listinfo/users</a>

</pre>
            </blockquote>
            <pre>May be the bar mode can help you
x=linspace(0,%pi,10);y=sin(x);
clf;plot(x,y);e=gce();e=e.children;
e.polyline_style=6;e.bar_width=0.5;
e.background=2;
e.line_mode="off";
_______________________________________________
users mailing list
 <a class="ecxmoz-txt-link-rfc2396E" href="mailto:users@lists.scilab.org"><mailto:users@lists.scilab.org></a> <a class="ecxmoz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
 <a class="ecxmoz-txt-link-rfc2396E" href="http://lists.scilab.org/mailman/listinfo/users" target="_blank"><http://lists.scilab.org/mailman/listinfo/users></a> <a class="ecxmoz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users" target="_blank">http://lists.scilab.org/mailman/listinfo/users</a>

</pre>
          </blockquote><br></blockquote></blockquote></blockquote></div>                                      </div></body>
</html>