Sunday, March 11, 2012

[Scilab] Plotting with Colors

There had been much frustration when I attempted to plot several locus lines of a four-bar linkage in a single graph. I struggled with the color settings. Searching around the web I find that much of the information given about the use of the plot and plot2d function failed to address how plotting single dots works.

Searching the Scilab online help, we get

plot



LineSpec
This option may be used to specify, in a short and easy manner, how the curves are drawn. It must always be a string containing references to LineStyle, Marker and Color specifiers.
These references must be set inside the string (order is not important) in an unambiguous way. For example, to specify a red long-dashed line with the diamond mark enabled, you can write : 'r--d' or '--dire' or '--reddiam' or another unambiguous statement... or to be totally complete 'diamondred--' (seeLineSpec).
Note that the line style and color, marks color (and sizes) can also be (re-)set throught the polyline entity properties (see polyline_properties).

plot2d



style
This option may be used to specify how the curves are drawn. If this option is specified, the associated value should be a vector with as many entries as curves.
  • if style(i) is strictly positive, the curve is drawn as plain line and style(i) defines the index of the color used to draw the curve (see getcolor). Note that the line style and the thickness can be set through the polyline entity properties (see polyline_properties).
    Piecewise linear interpolation is done between the given curve points.
  • if style(i) is negative or zero, the given curve points are drawn using marks, abs(style(i))defines the mark with id used. Note that the marks color and marks sizes can be set through the polyline entity properties (see polyline_properties).

Pretty clear. So what's the problem?
If I were to do a plot consisting of three "points," say, (1,2), (3,4), and (5,6). They are to be presented as (1) a dot with default color, (2)a red default mark, and (3)a red dot. Using plot, the commend lines would be:
plot(1,2,'.')
plot(3,4,'r')
plot(5,6,'r.')
Whereas using plot2d the commend lines should, according to most tutorials,
plot2d(1,2,style=0), plot2d(1,2,style(0), or plot2d(1,2,0)
X plot2d(3,4,style=1), plot2d(3,4,style(1)), or plot2d(3,4,1)
X plot2d(5,6, style=[0,1], or plot(5,6,[0,1])

The second line is fine if I were plotting lines. (The figure shows the results of the first four commends.) However, not setting the mark style will result in an empty plot. To solve this problem, we would have to change the global property of the plot. I have not yet managed this part, but I shall update it as soon as I figure out how. Stay tuned.

No comments:

Post a Comment