1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) INRIA - Fabrice Leray
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2018 - 2019 - Samuel GOUGEON
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
18 xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
19 xml:lang="en" xml:id="plot">
21 <refname>plot</refname>
22 <refpurpose>2D plot</refpurpose>
31 plot(x, list(fun, param))
33 plot(.., LineSpec, GlobalProperty)
34 plot(x1, y1, LineSpec1, x2,y2,LineSpec2,...xN, yN, LineSpecN, GlobalProperty1,.. GlobalPropertyM)
35 plot(x1,fun1,LineSpec1, x2,y2,LineSpec2,...xN,funN,LineSpecN, GlobalProperty1, ..GlobalPropertyM)
41 <title>Arguments</title>
47 vector or matrix of real numbers or integers. If omitted, it is assumed
48 to be the vector <literal>1:n</literal> where <literal>n</literal> is the
49 number of curve points given by the <literal>y</literal> parameter.
57 vector or matrix of real numbers or of integers.
62 <term>fun, fun1, ..</term>
65 handle of a function, as in <literal>plot(x, sin)</literal>.
68 If the function to plot needs some parameters as input arguments, the
69 function and its parameters can be specified through a list, as in
70 <literal>plot(x, list(delip, -0.4))</literal>
77 <para>This optional argument must be a string that will be used as a
78 shortcut to specify a way of drawing a line. We can have one
79 <literal>LineSpec</literal> per <literal>y</literal> or <literal>{x,y}</literal>
80 previously entered. <literal>LineSpec</literal> options deals with
81 LineStyle, Marker and Color specifiers (see <link linkend="LineSpec">LineSpec</link>).
82 Those specifiers determine the line style, mark style and color of
88 <term>GlobalProperty</term>
90 <para>This optional argument represents a sequence of couple
91 statements <literal>{PropertyName,PropertyValue}</literal> that defines
92 global objects' properties applied to all the curves created by this
93 plot. For a complete view of the available properties (see
94 <link linkend="GlobalProperty">GlobalProperty</link>).
102 "ln" | "nl" | "ll" : 2-character word made of "l" standing for
103 "<emphasis role="bold">L</emphasis>ogarithmic" or/and "n" standing for
104 "<emphasis role="bold">N</emphasis>ormal". The first character applies to
105 the X axis, the second to the Y axis. Hence, "ln" means that the X axis
106 is logarithmic and the Y axis is normal. The default is "nn":
107 both axes in normal scales.
110 <literal>logflag</literal> must be used after <literal>axes_handle</literal>
111 (if any) and before the first curve's data <literal>x</literal> or
112 <literal>y</literal> or <literal>fun</literal>.
113 It applies to all curves drawn by the <literal>plot(…)</literal> instruction.
118 <term>axes_handle</term>
120 <para>This optional argument forces the plot to appear inside the
121 selected axes given by <literal>axes_handle</literal> rather than the
122 current axes (see <link linkend="gca">gca</link>).
129 <title>Description</title>
131 <literal>plot</literal> plots a set of 2D curves. <literal>plot</literal> has been
132 rebuild to better handle Matlab syntax. To improve graphical
133 compatibility, Matlab users should use <literal>plot</literal> (rather than
134 <link linkend="plot2d">plot2d</link>).
136 <para>Data entry specification :</para>
137 <para>In this paragraph and to be more clear, we won't mention
138 <literal>LineSpec</literal> nor <literal>GlobalProperty</literal> optional arguments
139 as they do not interfere with entry data (except for <literal>"Xdata"</literal>,
140 <literal>"Ydata"</literal> and <literal>"Zdata"</literal> property, see
141 <link linkend="GlobalProperty">GlobalProperty</link>). It is assumed that all those optional
142 arguments could be present too.
145 If <literal>y</literal> is a vector, plot(y) plots vector <literal>y</literal>
146 versus vector <literal>1:size(y,'*')</literal>.
149 If <literal>y</literal> is a matrix, plot(y) plots each columns of
150 <literal>y</literal> versus vector <literal>1:size(y,1)</literal>.
153 If <literal>x</literal> and <literal>y</literal> are vectors, plot(x,y) plots
154 vector <literal>y</literal> versus vector <literal>x</literal>. <literal>x</literal> and
155 <literal>y</literal> vectors should have the same number of entries.
158 If <literal>x</literal> is a vector and <literal>y</literal> a matrix plot(x,y)
159 plots each columns of <literal>y</literal> versus vector <literal>x</literal>. In this
160 case the number of columns of <literal>y</literal> should be equal to the number
161 of <literal>x</literal> entries.
164 If <literal>x</literal> and <literal>y</literal> are matrices, plot(x,y) plots each
165 columns of <literal>y</literal> versus corresponding column of <literal>x</literal>.
166 In this case the <literal>x</literal> and <literal>y</literal> sizes should be the
170 Finally, if only <literal>x</literal> or <literal>y</literal> is a matrix, the
171 vector is plotted versus the rows or columns of the matrix. The choice is
172 made depending on whether the vector's row or column dimension matches the
173 matrix row or column dimension. In case of a square matrix (on
174 <literal>x</literal> or <literal>y</literal> only), priority is given to columns
175 rather than lines (see examples below).
179 When it is necessary and possible, <literal>plot</literal> transposes
180 <literal>x</literal> and <literal>y</literal>,
181 to get compatible dimensions; a warning is then issued. For instance,
182 when <literal>x</literal> has as many rows as <literal>y</literal> has columns.
183 If <literal>y</literal> is square, it is never transposed.
187 <literal>y</literal> can also be a function defined as a macro or a
188 primitive. In this case, <literal>x</literal> data must be given (as a vector or
189 matrix) and the corresponding computation <literal>y(x)</literal> is done
193 The <literal>LineSpec</literal> and <literal>GlobalProperty</literal> arguments
194 should be used to customize the plot. Here is a complete list of the
199 <term>LineSpec</term>
201 <para>This option may be used to specify, in a short and easy manner,
202 how the curves are drawn. It must always be a string containing
203 references to LineStyle, Marker and Color specifiers.
205 <para>These references must be set inside the string (order is not
206 important) in an unambiguous way. For example, to specify a red
207 long-dashed line with the diamond mark enabled, you can write :
208 <literal>'r--d'</literal> or <literal>'--dire'</literal> or
209 <literal>'--reddiam'</literal> or another unambiguous statement... or to be
210 totally complete <literal>'diamondred--'</literal> (see
211 <link linkend="LineSpec">LineSpec</link>).
213 <para>Note that the line style and color, marks color (and sizes) can
214 also be (re-)set through the polyline entity properties (see
215 <link linkend="polyline_properties">polyline_properties</link>).
220 <term>GlobalProperty</term>
222 <para>This option may be used to specify how all the curves are
223 plotted using more option than via <literal>LineSpec</literal>. It must
224 always be a couple statement constituted of a string defining the
225 <literal>PropertyName</literal>, and its associated value
226 <literal>PropertyValue</literal> (which can be a string or an integer or...
227 as well depending on the type of the <literal>PropertyName</literal>). Using
228 <literal>GlobalProperty</literal>, you can set multiple properties : every
229 properties available via LineSpec and more : the marker color
230 (foreground and background), the visibility, clipping and thickness of
231 the curves. (see <link linkend="GlobalProperty">GlobalProperty</link>)
233 <para>Note that all these properties can be (re-)set through the
234 polyline entity properties (see <link linkend="polyline_properties">polyline_properties</link>).
241 <title>Remarks</title>
242 <para>By default, successive plots are superposed. To clear the previous
243 plot, use <literal>clf()</literal>. To enable <literal>auto_clear</literal> mode as
244 the default mode, edit your default axes doing:
246 <para>da=gda();</para>
247 <para>da.auto_clear = 'on'</para>
249 For a better display <literal>plot</literal> function may modify the <literal>box</literal> property of
250 its parent Axes. This happens when the parent Axes were created by the call to <literal>plot</literal> or were empty
251 before the call. If one of the axis is centered at origin,
253 Otherwise, the box is enabled.
256 For more information about box property and axis positioning see <link linkend="axes_properties">axes_properties</link>
258 <para>A default color table is used to color plotted curves if you do not
259 specify a color. When drawing multiple lines, the plot command
260 automatically cycles through this table. Here are the used colors:
262 <informaltable border="1">
264 <th> <literal>R</literal> </th>
265 <th> <literal>G</literal> </th>
266 <th> <literal>B</literal> </th>
268 <tr> <td>0.</td> <td>0.</td> <td>1.</td> </tr>
269 <tr> <td>0.</td> <td>0.5</td> <td>0.</td> </tr>
270 <tr> <td>1.</td> <td>0.</td> <td>0.</td> </tr>
271 <tr> <td>0.</td> <td>0.75</td> <td>0.75</td> </tr>
272 <tr> <td>0.75</td> <td>0.</td> <td>0.75</td> </tr>
273 <tr> <td>0.75</td> <td>0.75</td> <td>0.</td> </tr>
274 <tr> <td>0.25</td> <td>0.25</td> <td>0.25</td> </tr>
278 Enter the command <literal>plot</literal> to see a demo.
282 <title>Examples</title>
284 <emphasis role="bold">Choosing the normal or logarithmic plotting mode:</emphasis>
286 <programlisting role="example"><![CDATA[
287 gda().grid = [1 1]*color("grey70");
288 title(gda(), "fontsize", 3, "color", "lightseagreen", "fontname", "helvetica bold");
290 x = linspace(1e-1,100,1000);
293 G = exp(-((x-xm)/dx).^2/2)*30;
296 subplot(2,2,1), plot(x, G), title("plot(x, y)")
297 subplot(2,2,2), plot("ln", x, G), title("semilog-x : plot(""ln"", x, y)"); gca().sub_ticks(1) = 8;
298 subplot(2,2,3), plot("nl", x, G), title("semilog-y : plot(""nl"", x, y)"); gca().sub_ticks(2) = 8;
299 subplot(2,2,4), plot("ll", x, G), title("loglog : plot(""ll"", x, y)"); gca().sub_ticks = [8 8];
304 gda().grid = [1 1]*color("grey70");
305 title(gda(), "", "fontsize", 3, "color", "lightseagreen", "fontname", "helvetica bold");
307 x = linspace(1e-1,100,1000);
310 G = exp(-((x-xm)/dx).^2/2)*30;
312 subplot(2,2,1), plot(x, G), title("plot(x, y)")
313 subplot(2,2,2), plot("ln", x, G), title("semilog-x : plot(""ln"", x, y)")
314 gca().sub_ticks(1) = 8;
315 subplot(2,2,3), plot("nl", x, G), title("semilog-y : plot(""nl"", x, y)")
316 gca().sub_ticks(2) = 8;
317 subplot(2,2,4), plot("ll", x, G), title("loglog : plot(""ll"", x, y)")
318 gca().sub_ticks = [8 8];
320 gcf().axes_size = [750 520];
325 <emphasis role="bold">Simple plot of a single curve:</emphasis>
327 <programlisting role="example"><![CDATA[
328 // Default abscissae = indices
330 plot(sin(0:0.1:2*%pi))
333 // With explicit abscissae:
337 xlabel("Specified abscissae")
340 // Default abscissae = indices
342 plot(sin(0:0.1:2*%pi))
345 // With explicit abscissae:
349 xlabel("Specified abscissae")
351 gcf().axes_size = [700 350];
355 <emphasis role="bold">Multiple curves with shared abscissae:</emphasis>
356 Y: 1 column = 1 curve:
358 <programlisting role="example"><![CDATA[
361 plot(x, [sin(x) sin(2*x) sin(3*x)])
365 plot(x,[sin(x) sin(2*x) sin(3*x)])
367 gcf().axes_size = [700 350];
371 <emphasis role="bold">
372 Specifying a macro or a builtin instead of explicit ordinates:
375 <programlisting role="example"><![CDATA[
377 subplot(2,2,1) // sin() is a builtin
378 plot(1:0.1:10, sin) // <=> plot(1:0.1:10, sin(1:0.1:10))
379 title("plot(x, sin)", "fontsize",3)
382 deff('y = myFun(x)','y = x + rand(x)')
384 plot(-3:0.1:5, myFun)
385 title("plot(x, myFun)", "fontsize",3)
387 // With functions with parameters:
389 plot(1:0.05:7, list(delip, -0.4)) // <=> plot(1:0.05:7, delip(1:0.05:7,-0.4) )
390 title("plot(x, list(delip,-0.4))", "fontsize",3)
392 function Y = myPow(x,p)
397 Y(:,i) = Y(:,i)/m(i);
402 plot(x, list(myPow,1:5))
403 title("plot(x, list(myPow,1:5))", "fontsize",3)
405 <scilab:image><![CDATA[
406 subplot(2,2,1) // sin() is a builtin
407 plot(1:0.1:10, sin) // <=> plot(1:0.1:10, sin(1:0.1:10))
408 title("plot(x,sin)", "fontsize",3)
411 deff('y = myFun(x)','y = x + rand(x)')
413 plot(-3:0.1:5, myFun)
414 title("plot(x, myFun)", "fontsize",3)
416 // With functions with parameters:
418 plot(1:0.05:7, list(delip, -0.4)) // <=> plot(1:0.05:7, delip(1:0.05:7,-0.4) )
419 title("plot(x, list(delip,-0.4))", "fontsize",3)
421 function Y = myPow(x,p)
426 Y(:,i) = Y(:,i)/m(i);
431 plot(x, list(myPow,1:5))
432 title("plot(x, list(myPow,1:5))", "fontsize",3)
434 gcf().axes_size = [730 500];
438 <emphasis role="bold">Setting curves simple styles when calling plot():</emphasis>
440 <programlisting role="example"><![CDATA[
442 t = -%pi:%pi/20:2*%pi;
443 // sin() : in Red, with O marks, without line
444 // cos() : in Green, with + marks, with a solid line
445 // gaussian: in Blue, without marks, with dotted line
446 gauss = 1.5*exp(-(t/2-1).^2)-1;
448 plot(t,sin,'ro', t,cos,'g+-', t,gauss,':b')
450 <scilab:image><![CDATA[
451 t = -%pi:%pi/20:2*%pi;
452 // sin() : in Red, with O marks, without line
453 // cos() : in Green, with + marks, with a solid line
454 // gaussian: in Blue, without marks, with dotted line
455 gauss = 1.5*exp(-(t/2-1).^2)-1;
457 plot(t,sin,'ro', t,cos,'g+-', t,gauss,':b')
459 gcf().axes_size = [800 400];
464 Vertical segments between two curves, with automatic colors, and using Global properties
465 for markers styles. Targeting a defined axes.
467 <programlisting role="example"><![CDATA[
470 ax3 = gca(); // We will draw here later
471 xsetech([0 0 0.7 1]) // Defines the first Axes area
473 // Tuning markers properties
474 plot([t ;t],[sin(t) ;cos(t)],'marker','d','markerFaceColor','green','markerEdgeColor','yel')
476 // Targeting a defined axes
479 <scilab:image><![CDATA[
482 ax3 = gca(); // We will draw here later
483 xsetech([0 0 0.7 1]) // Defines the first Axes area
485 // Tuning markers properties
486 plot([t ;t],[sin(t) ;cos(t)],'marker','d','markerFaceColor','green','markerEdgeColor','yel')
488 // Targeting a defined axes
491 gcf().axes_size = [800 400];
497 <emphasis role="bold">Case of a non-square Y matrix:</emphasis>
498 When it is consistent and required, X or/and Y data are
499 automatically transposed in order to become plottable.
501 <programlisting role="example"><![CDATA[
509 // Only one matching possibility case: how to make 4 identical plots in 4 manners...
510 // x is 1x4 (vector) and y is 4x5 (non square matrix)
511 subplot(221); plot(x', y , "o-"); // OK as is
512 subplot(222); plot(x , y , "o-"); // x is transposed
513 subplot(223); plot(x', y', "o-"); // y is transposed
514 subplot(224); plot(x , y', "o-"); // x and y are transposed
523 // Only one matching possibility case: how to make 4 identical plots in 4 manners...
524 // x is 1x4 (vector) and y is 4x5 (non square matrix)
525 subplot(221); plot(x', y , "o-"); // OK as is
526 subplot(222); plot(x , y , "o-"); // x is transposed
527 subplot(223); plot(x', y', "o-"); // y is transposed
528 subplot(224); plot(x , y', "o-"); // x and y are transposed
531 <emphasis role="bold">Case of a square Y matrix, and X implicit or square:</emphasis>
533 <programlisting role="example"><![CDATA[
540 subplot(231), plot(t,"o-") , title("plot(t)", "fontsize",3)
541 subplot(234), plot(t',"o-"), title("plot(t'')", "fontsize",3)
543 subplot(232), plot(t,t,"o-") , title("plot(t, t)", "fontsize",3)
544 subplot(233), plot(t,t',"o-"), title("plot(t,t'')", "fontsize",3)
546 subplot(235), plot(t', t,"o-"), title("plot(t'', t)", "fontsize",3)
547 subplot(236), plot(t', t',"o-"), title("plot(t'', t'')", "fontsize",3)
549 for i=1:6, gcf().children(i).data_bounds([1 3]) = 0.5; end
558 subplot(231), plot(t,"o-") , title("plot(t)", "fontsize",3)
559 subplot(234), plot(t',"o-"), title("plot(t'')", "fontsize",3)
561 subplot(232), plot(t,t,"o-") , title("plot(t, t)", "fontsize",3)
562 subplot(233), plot(t,t',"o-"), title("plot(t,t'')", "fontsize",3)
564 subplot(235), plot(t', t,"o-"), title("plot(t'', t)", "fontsize",3)
565 subplot(236), plot(t', t',"o-"), title("plot(t'', t'')", "fontsize",3)
567 for i=1:6, gcf().children(i).data_bounds([1 3]) = 0.5; end
569 gcf().axes_size = [800 450];
573 <emphasis role="bold">Special cases of a matrix X and a vector Y:</emphasis>
575 <programlisting role="example"><![CDATA[
583 subplot(221), plot(X, y, "o-"), title("plot(X, row)", "fontsize",3)
584 // equivalent to plot(t, [1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4])
585 subplot(223), plot(X, y', "o-"), title("plot(X, col) (row = col'')", "fontsize",3)
586 subplot(222), plot(X',y, "o-"), title("plot(X'', row)", "fontsize",3)
587 subplot(224), plot(X',y', "o-"), title("plot(X'', col) (row = col'')", "fontsize",3)
589 for i = 1:4, gcf().children(i).data_bounds([1 3]) = 0.5; end
599 subplot(221), plot(X, y, "o-"), title("plot(X, row)", "fontsize",3)
600 // equivalent to plot(t, [1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4])
601 subplot(223), plot(X, y', "o-"), title("plot(X, col) (row = col'')", "fontsize",3)
602 subplot(222), plot(X',y, "o-"), title("plot(X'', row)", "fontsize",3)
603 subplot(224), plot(X',y', "o-"), title("plot(X'', col) (row = col'')", "fontsize",3)
605 for i = 1:4, gcf().children(i).data_bounds([1 3]) = 0.5; end
610 <emphasis role="bold">Post-tuning Axes and curves:</emphasis>
612 <programlisting role="example"><![CDATA[
614 plot(x-4,sin(x), x+2,cos(x))
616 // axis centered at (0,0)
617 a=gca(); // Handle on axes entity
618 a.x_location = "origin";
619 a.y_location = "origin";
621 // Some operations on entities created by plot ...
623 a.children // list the children of the axes : here it is an Compound child composed of 2 entities
624 poly1= a.children.children(2); //store polyline handle into poly1
625 poly1.foreground = 4; // another way to change the style...
626 poly1.thickness = 3; // ...and the thickness of a curve.
627 poly1.clip_state='off' // clipping control
632 plot(x-4,sin(x),x+2,cos(x))
634 a.x_location = "origin";
635 a.y_location = "origin";
638 poly1 = a.children.children(2);
639 poly1.foreground = 4;
641 poly1.clip_state='off'
645 <refsection role="see also">
646 <title>See also</title>
647 <simplelist type="inline">
649 <link linkend="plot2d">plot2d</link>
652 <link linkend="plot2d2">plot2d2</link>
655 <link linkend="plot2d3">plot2d3</link>
658 <link linkend="plot2d4">plot2d4</link>
661 <link linkend="param3d">param3d</link>
664 <link linkend="surf">surf</link>
667 <link linkend="scf">scf</link>
670 <link linkend="clf">clf</link>
673 <link linkend="xdel">xdel</link>
676 <link linkend="delete">delete</link>
679 <link linkend="LineSpec">LineSpec</link>
682 <link linkend="color_list">Named colors</link>
685 <link linkend="GlobalProperty">GlobalProperty</link>
689 <refsection role="history">
690 <title>History</title>
693 <revnumber>6.0.1</revnumber>
695 The "color"|"foreground", "markForeground", and "markBackground" GlobalProperty
696 colors can now be chosen among the full predefined colors list, or by
697 their "#RRGGBB" hexadecimal codes, or by their indices in the colormap.
701 <revnumber>6.0.2</revnumber>
703 Plotting a function fun(x, params) with input parameters is now possible with
704 plot(x, list(fun, params)).
708 <revnumber>6.1.0</revnumber>
710 logflag option added.