File: handle_plot.html

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 (181 lines) | stat: -rw-r--r-- 9,585 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>FreeMat: PLOT Plot Function</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">FreeMat
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('handle_plot.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">PLOT Plot Function </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Section: <a class="el" href="sec_handle.html">Handle-Based Graphics</a> </p>
<h1><a class="anchor" id="Usage"></a>
Usage</h1>
<p>This is the basic plot command for FreeMat. The general syntax for its use is </p>
<pre class="fragment">  plot(\&lt;data 1\&gt;,{linespec 1},\&lt;data 2\&gt;,{linespec 2}...,properties...)
</pre><p> where the <code>&lt;data&gt;</code> arguments can have various forms, and the <code>linespec</code> arguments are optional. We start with the <code>&lt;data&gt;</code> term, which can take on one of multiple forms: </p>
<ul>
<li>
Vector Matrix Case &ndash; In this case the argument data is a pair of variables. A set of <code>x</code> coordinates in a numeric vector, and a set of <code>y</code> coordinates in the columns of the second, numeric matrix. <code>x</code> must have as many elements as <code>y</code> has columns (unless <code>y</code> is a vector, in which case only the number of elements must match). Each column of <code>y</code> is plotted sequentially against the common vector <code>x</code>.  </li>
<li>
Unpaired Matrix Case &ndash; In this case the argument data is a single numeric matrix <code>y</code> that constitutes the <code>y</code>-values of the plot. An <code>x</code> vector is synthesized as <code>x = 1:length(y)</code>, and each column of <code>y</code> is plotted sequentially against this common <code>x</code> axis.  </li>
<li>
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.  </li>
</ul>
<p>Multiple data arguments in a single plot command are treated as a <b>sequence</b>, meaning that all of the plots are overlapped on the same set of axes. The <code>linespec</code> is a string used to change the characteristics of the line. In general, the <code>linespec</code> is composed of three optional parts, the <code>colorspec</code>, the <code>symbolspec</code> and the <code>linestylespec</code> in any order. Each of these specifications is a single character that determines the corresponding characteristic. First, the <code>colorspec</code>: </p>
<ul>
<li>
<code>'b'</code> - Color Blue  </li>
<li>
<code>'g'</code> - Color Green  </li>
<li>
<code>'r'</code> - Color Red  </li>
<li>
<code>'c'</code> - Color Cyan  </li>
<li>
<code>'m'</code> - Color Magenta  </li>
<li>
<code>'y'</code> - Color Yellow  </li>
<li>
<code>'k'</code> - Color Black  </li>
</ul>
<p>The <code>symbolspec</code> specifies the (optional) symbol to be drawn at each data point: </p>
<ul>
<li>
<code>'.'</code> - Dot symbol  </li>
<li>
<code>'o'</code> - Circle symbol  </li>
<li>
<code>'x'</code> - Times symbol  </li>
<li>
<code>'+'</code> - Plus symbol  </li>
<li>
<code>'*'</code> - Asterisk symbol  </li>
<li>
<code>'s'</code> - Square symbol  </li>
<li>
<code>'d'</code> - Diamond symbol  </li>
<li>
<code>'v'</code> - Downward-pointing triangle symbol  </li>
<li>
<code>'^'</code> - Upward-pointing triangle symbol  </li>
<li>
<code>'&lt;'</code> - Left-pointing triangle symbol  </li>
<li>
<code>'&gt;'</code> - Right-pointing triangle symbol  </li>
</ul>
<p>The <code>linestylespec</code> specifies the (optional) line style to use for each data series: </p>
<ul>
<li>
<code>'-'</code> - Solid line style  </li>
<li>
<code>':'</code> - Dotted line style  </li>
<li>
<code>'-.'</code> - Dot-Dash-Dot-Dash line style  </li>
<li>
<code>'&ndash;'</code> - Dashed line style  </li>
</ul>
<p>For sequences of plots, the <code>linespec</code> is recycled with color order determined by the properties of the current axes. You can also use the <code>properties</code> 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 <code>plot</code> operation. </p>
<pre class="fragment">  handle = plot(handle,...)
</pre> <h1><a class="anchor" id="Example"></a>
Example</h1>
<p>The most common use of the <code>plot</code> 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 <code>linespec</code> of <code>'r-'</code>).</p>
<pre class="fragment">--&gt; x = linspace(-pi,pi);
--&gt; y = cos(x);
--&gt; plot(x,y,'r-');
</pre><p>which results in the following plot. </p>
<div class="image">
<img src="plot1.png" alt="plot1.png"/>
</div>
 <p>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.</p>
<pre class="fragment">--&gt; x = linspace(-pi,pi);
--&gt; y = [cos(x(:)),cos(3*x(:)),cos(5*x(:))];
--&gt; plot(x,y);
</pre><p>In this case, we do not specify a <code>linespec</code>, so that we cycle through the colors automatically (in the order listed in the previous section). </p>
<div class="image">
<img src="plot2.png" alt="plot2.png"/>
</div>
 <p>This time, we produce the same plot, but as we want to assign individual <code>linespec</code>s 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 <code>linespec</code> 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.</p>
<pre class="fragment">--&gt; plot(x,y(:,1),'rx-',x,y(:,2),'b&gt;-',x,y(:,3),'g*:');
</pre><div class="image">
<img src="plot3.png" alt="plot3.png"/>
</div>
 <p>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.</p>
<pre class="fragment">--&gt; plot(y(:,1),'r:',y(:,2),'b;',y(:,3),'g|');
</pre><p>Note in the resulting plot that the <code>x</code>-axis no longer runs from <code>[-pi,pi]</code>, but instead runs from <code>[1,100]</code>. </p>
<div class="image">
<img src="plot4.png" alt="plot4.png"/>
</div>
 <p>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.</p>
<pre class="fragment">--&gt; y = cos(2*x) + i * cos(3*x);
--&gt; plot(y);
</pre><div class="image">
<img src="plot5.png" alt="plot5.png"/>
</div>
 <p>Here is an example of using the handle properties to influence the behavior of the generated lines.</p>
<pre class="fragment">--&gt; t = linspace(-3,3);
--&gt; plot(cos(5*t).*exp(-t),'r-','linewidth',3);
</pre><div class="image">
<img src="plot6.png" alt="plot6.png"/>
</div>
  </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="index.html">FreeMat Documentation</a></li><li class="navelem"><a class="el" href="sec_handle.html">Handle-Based Graphics</a></li>
    <li class="footer">Generated on Thu Jul 25 2013 18:58:28 for FreeMat by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.1 </li>
  </ul>
</div>
</body>
</html>