[Scilab-users] How to produce a filled staircase plot
Rafael Guerra
jrafaelbguerra at hotmail.com
Thu Oct 8 13:24:07 CEST 2015
Very ingenious matrix trick, I loved it
Date: Wed, 7 Oct 2015 11:47:49 +0200
From: Serge.Steer at inria.fr
To: users at lists.scilab.org
Subject: Re: [Scilab-users] How to produce a filled staircase plot
Under Scilab-5.5.2 xfpoly rescale the
graph automatically as plot does
A little more simple (efficient?) code:
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=matrix([t' t($); t' t($)],-1,1);
N2=matrix([0 N'; N' 0],-1,1)
clf;
xfpoly(t2,N2);
h = gce();
h.line_mode = "off";
h.background = color('gray');
plot(t2(2:$-1),N2(2:$-1),'black',
t2(2:$-1),21*exp(-t2(2:$-1)/2),'red');
Le 07/10/2015 09:58, Antoine Monmayrant a écrit :
Le 10/07/2015 09:41 AM, Yann DEBRAY a
écrit :
Hello Raphael,
Nice plot, but sadly it doesn't rescale.
Do you have an idea how to make it fit the axes, to rescale
automatically?
You can calculate your data_bounds and set them after plotting.
Alernatively, use my method that does not rely on xfpoly, but on
plot that rescales automatically:
//I want to staircase plot N(Decay_times)
N=[N2,N2-cumsum(ones(Decay_times))+1];
Np1=[N2-cumsum(ones(Decay_times))+1,0];
Ns=matrix([N;Np1],2*prod(size(N)));
Decay_times=[0,Decay_times];
D_t=matrix([Decay_times;Decay_times],2*prod(size(Decay_times)));
//in the end, I plot Ns(D_t)
Ns=[0;Ns];
D_t=[0;D_t];
//plot it
plot(D_t,Ns, 'k-');
//fill the bacground
e=gce();
e.children.polyline_style=1;
e.children.closed='off';
e.children.background=color('gray');
Yann
Le 07/10/2015 00:17, Rafael Guera a
écrit :
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 [mailto:users-bounces at lists.scilab.org] On Behalf Of Antoine Monmayrant
Sent: Tuesday, October 06, 2015 10:57 AM
To: Users mailing list for Scilab <users at lists.scilab.org>
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 < <mailto:Serge.Steer at inria.fr> Serge.Steer at inria.fr> a écrit:
Le 06/10/2015 00:01, Antoine Monmayrant a écrit :
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
<mailto:users at lists.scilab.org> users at lists.scilab.org
<http://lists.scilab.org/mailman/listinfo/users> http://lists.scilab.org/mailman/listinfo/users
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
<mailto:users at lists.scilab.org> users at lists.scilab.org
<http://lists.scilab.org/mailman/listinfo/users> http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20151008/a7861563/attachment.htm>
More information about the users
mailing list