File: plot.mdc

package info (click to toggle)
freemat 4.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 141,800 kB
  • ctags: 14,082
  • sloc: ansic: 126,788; cpp: 62,046; python: 2,080; perl: 1,255; sh: 1,146; yacc: 1,019; lex: 239; makefile: 100
file content (156 lines) | stat: -rw-r--r-- 5,264 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

 Usage

This is the basic plot command for FreeMat. The general
syntax for its use is

    plot(\<data 1\>,{linespec 1},\<data 2\>,{linespec
  2}...,properties...)

where the <data> arguments can have various forms, and the
linespec arguments are optional. We start with the <data>
term, which can take on one of multiple forms:

* Vector Matrix Case &ndash; In this case the argument data
  is a pair of variables. A set of x coordinates in a
  numeric vector, and a set of y coordinates in the columns
  of the second, numeric matrix. x must have as many
  elements as y has columns (unless y is a vector, in which
  case only the number of elements must match). Each column
  of y is plotted sequentially against the common vector x.
* Unpaired Matrix Case &ndash; In this case the argument
  data is a single numeric matrix y that constitutes the y-
  values of the plot. An x vector is synthesized as x = 1:
  length(y), and each column of y is plotted sequentially
  against this common x axis.
* Complex Matrix Case &ndash; Here the argument data is a
  complex matrix, in which case, the real part of each
  column is plotted against the imaginary part of each
  column. All columns receive the same line styles.

Multiple data arguments in a single plot command are treated
as a sequence, meaning that all of the plots are overlapped
on the same set of axes. The linespec is a string used to
change the characteristics of the line. In general, the
linespec is composed of three optional parts, the colorspec,
the symbolspec and the linestylespec in any order. Each of
these specifications is a single character that determines
the corresponding characteristic. First, the colorspec:

* 'b' - Color Blue
* 'g' - Color Green
* 'r' - Color Red
* 'c' - Color Cyan
* 'm' - Color Magenta
* 'y' - Color Yellow
* 'k' - Color Black

The symbolspec specifies the (optional) symbol to be drawn
at each data point:

* '.' - Dot symbol
* 'o' - Circle symbol
* 'x' - Times symbol
* '+' - Plus symbol
* '*' - Asterisk symbol
* 's' - Square symbol
* 'd' - Diamond symbol
* 'v' - Downward-pointing triangle symbol
* '^' - Upward-pointing triangle symbol
* '<' - Left-pointing triangle symbol
* '>' - Right-pointing triangle symbol

The linestylespec specifies the (optional) line style to use
for each data series:

* '-' - Solid line style
* ':' - Dotted line style
* '-.' - Dot-Dash-Dot-Dash line style
* '&ndash;' - Dashed line style

For sequences of plots, the linespec is recycled with color
order determined by the properties of the current axes. You
can also use the properties argument to specify handle
properties that will be inherited by all of the plots
generated during this event. Finally, you can also specify
the handle for the axes that are the target of the plot
operation.

    handle = plot(handle,...)



 Example

The most common use of the plot command probably involves
the vector-matrix paired case. Here, we generate a simple
cosine, and plot it using a red line, with no symbols (i.e.,
a linespec of 'r-').

  --> x = linspace(-pi,pi);
  --> y = cos(x);
  --> plot(x,y,'r-');

which results in the following plot.
 plot1.png
Next, we plot multiple sinusoids (at different frequencies).
First, we construct a matrix, in which each column
corresponds to a different sinusoid, and then plot them all
at once.

  --> x = linspace(-pi,pi);
  --> y = [cos(x(:)),cos(3*x(:)),cos(5*x(:))];
  --> plot(x,y);

In this case, we do not specify a linespec, so that we cycle
through the colors automatically (in the order listed in the
previous section).
 plot2.png
This time, we produce the same plot, but as we want to
assign individual linespecs to each line, we use a sequence
of arguments in a single plot command, which has the effect
of plotting all of the data sets on a common axis, but which
allows us to control the linespec of each plot. In the
following example, the first line (harmonic) has red, solid
lines with times symbols marking the data points, the second
line (third harmonic) has blue, solid lines with right-
pointing triangle symbols, and the third line (fifth
harmonic) has green, dotted lines with asterisk symbols.

  --> plot(x,y(:,1),'rx-',x,y(:,2),'b>-',x,y(:,3),'g*:');

 plot3.png
The second most frequently used case is the unpaired matrix
case. Here, we need to provide only one data component,
which will be automatically plotted against a vector of
natural number of the appropriate length. Here, we use a
plot sequence to change the style of each line to be dotted,
dot-dashed, and dashed.

  --> plot(y(:,1),'r:',y(:,2),'b;',y(:,3),'g|');

Note in the resulting plot that the x-axis no longer runs
from [-pi,pi], but instead runs from [1,100].
 plot4.png
The final case is for complex matrices. For complex
arguments, the real part is plotted against the imaginary
part. Hence, we can generate a 2-dimensional plot from a
vector as follows.

  --> y = cos(2*x) + i * cos(3*x);
  --> plot(y);

 plot5.png
Here is an example of using the handle properties to
influence the behavior of the generated lines.

  --> t = linspace(-3,3);
  --> plot(cos(5*t).*exp(-t),'r-','linewidth',3);

 plot6.png

* FreeMat_Documentation
* Handle-Based_Graphics
* Generated on Thu Jul 25 2013 17:17:25 for FreeMat by
  doxygen_ 1.8.1.1