-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph.html
More file actions
270 lines (233 loc) · 18 KB
/
Copy pathgraph.html
File metadata and controls
270 lines (233 loc) · 18 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!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"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>graph</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: x-large}
.style2 {font-size: xx-large}
-->
</style>
<!-- InstanceEndEditable -->
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutDefaultTable-->
<tr>
<td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td>
<td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p> </p> </td>
<td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p>
<p class="Normal">If you're new to Python <br />
and VPython: <a href="VisualIntro.html">Introduction</a></p>
<p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p>
<p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p>
<p class="Normal">Choose an object:</p>
<select name="jumpMenu4" id="jumpMenu4" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose an object</option>
<option value="cylinder.html">Overview</option>
<option value="arrow.html">arrow</option>
<option value="box.html">box</option>
<option value="cone.html">cone</option>
<option value="convex.html">convex</option>
<option value="curve.html">curve</option>
<option value="cylinder.html">cylinder</option>
<option value="ellipsoid.html">ellipsoid</option>
<option value="extrusion.html">extrusion</option>
<option value="faces.html">faces</option>
<option value="frame.html">frame</option>
<option value="helix.html">helix</option>
<option value="label.html">label</option>
<option value="lights.html">lights</option>
<option value="points.html">points</option>
<option value="pyramid.html">pyramid</option>
<option value="ring.html">ring</option>
<option value="sphere.html">sphere</option>
<option value="text.html">text</option>
</select>
<p class="Normal">Work with objects:</p>
<select name="jumpMenu4" id="jumpMenu5" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose an option</option>
<option value="color.html">Color/Opacity</option>
<option value="materials.html">Materials/Textures</option>
<option value="shapes.html">Shapes Library</option>
<option value="paths.html">Paths Library</option>
<option value="defaults.html">Defaults</option>
<option value="rate.html">Animation Speed</option>
<option value="rotation.html">Rotations</option>
<option value="options.html">Additional Options</option>
<option value="delete.html">Delete an Object</option>
<option value="float.html">3/4 = 0?</option>
<option value="controls.html">Buttons/Sliders</option>
<option value="graph.html">Graphs</option>
<option value="lights.html">Lighting</option>
<option value="files.html">Read/Write Files</option>
<option value="trail.html">Leaving a Trail</option>
<option value="vector.html">Vector Operations </option>
<option value="factorial.html">factorial/combin</option>
</select>
<p class="Normal">Windows & Events:</p>
<select name="jumpMenu4" id="jumpMenu6" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose a topic</option>
<option value="display.html">Windows</option>
<option value="mouse.html">Mouse Events</option>
<option value="mouse_click.html"> Mouse Click</option>
<option value="mouse_drag.html"> Mouse Drag</option>
<option value="keyboard.html">Keyboard Events</option>
</select>
<p class="Normal">What's new in <a href="new_features.html">Visual 5</a></p>
<p class="Normal"><a href="http://vpython.org" target="_blank">VPython web site</a><br />
<a href="license.txt" target="_blank">Visual license</a><br />
<a href="http://www.python.org" target="_blank">Python web site</a> <br />
<a href="http://www.python.org/doc/2.5.2/lib/module-math.html" target="_blank">Math module</a> (sqrt etc.)<br />
<a href="http://www.scipy.org/Documentation" target="_blank">Numpy module</a> (arrays) </p></td>
<td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td>
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
<div>
<table width="100%" border="1">
<tr>
<td width="47%"><div align="center"><span class="style1 style2"><font color="#0000A0">Graphs</font></span></div></td>
<td width="53%"><div align="center"><a href="arrow.html"></a><a href="graph.html"><img src="images/graph.jpg" alt="graph" width="450" height="207" /></a></div></td>
</tr>
</table>
</div>
<p class="Normal">In this section we describe features for plotting graphs
with tick marks and labels. In the image above the user is dragging the mouse to see the coordinates at the intersection of the crosshairs. This image comes from the VPython demo program <span class="attribute">graphtest.py</span>. Graphs can also be log-log or semilog (see below).</p>
<p class="Normal">Here is a simple example of how to plot a graph (arange creates a numeric array running from 0 to 8, stopping short of 8.1):</p>
<p class="program"> from visual.graph import * # import graphing features
<br />
f1 = gcurve(color=color.cyan) # a graphics curve<br />
for x in arange(0, 8.05, 0.1): # x goes from 0 to 8<br />
f1.plot(pos=(x,5*cos(2*x)*exp(-0.2*x))) # plot </p>
<p class="Normal">Importing from <span class="attribute">visual.graph</span> makes available all Visual objects plus the graph plotting module. The graph
is autoscaled to display all the data in the window. </p>
<p class="Normal"> A connected curve (<span class="attribute">gcurve</span>)
is just one of several kinds of graph plotting objects. Other options are
disconnected dots (<span class="attribute">gdots</span>),
vertical bars (<span class="attribute">gvbars</span>), horizontal bars (<span class="attribute">ghbars</span>),
and binned data displayed as vertical bars (<span class="attribute">ghistogram</span>;
see later discussion). </p>
<p class="Normal">When creating <span class="attribute">gcurve</span>, <span class="attribute">gdots</span>, <span class="attribute">gvbars</span>, or <span class="attribute">ghbars</span>, you can optionally give a list of data points, such as pos=[(10,20), (50,30), (-5,-3)], or specify
a color, such as color=color.cyan. After creating one of these graphing objects, you can add a single point or a list of additional points:</p>
<p class="program"> f1.plot(pos=(100,-30)) # add a single point<br />
f1.plot(pos=[(100,-30),(20,50),(0,-10)]) # add a list<br />
</p>
<p class="Normal">When you add points, you can optionally specify a color for these points that is different from the default color of the object:</p>
<p class="program"> f1.plot(pos=(100,-30), color=color.red)</p>
<p class="Normal"> You can plot more than one thing on the same graph:</p>
<p class="program"> f1 = gcurve(color=color.cyan) <br />
f2 = gvbars(delta=0.05, color=color.blue)<br />
for x in arange(0., 8.05, 0.1): <br />
f1.plot(pos=(x,5*cos(2*x)*exp(-0.2*x))) # curve<br />
f2.plot(pos=(x,4*cos(0.5*x)*exp(-0.1*x)))# vbars</p>
<p class="Normal"><strong><font color="#0000A0">Special options for gcurve, gdots, gvbars, and ghbars</font></strong></p>
<p class="Normal">For <span class="attribute">gcurve</span> if you
specify <span class="attribute">dot=True</span> the current plotting
point is highlighted with a dot, which is particularly useful if
a graph retraces its path. You can specify a <span class="attribute">shape</span> attribute "round" or "square" (default
is <span class="attribute">shape="round"</span>) and a <span class="attribute">size</span> attribute,
which specifies the width of the dot in pixels (default is <span class="attribute">size=8</span>).
By default the dot has the same color as the gcurve, but you can
specify a different color, as in <span class="attribute">dot_color=color.green</span>.</p>
<p class="Normal">For <span class="attribute">gdots</span> you can specify a <span class="attribute">shape</span> attribute "round" or "square" (default is <span class="attribute">shape="round"</span>) and a <span class="attribute">size</span> attribute, which
specifies the width of the dot in pixels (default is <span class="attribute">size=5</span>).</p>
<p class="Normal">For <span class="attribute">gvbars</span> and <span class="attribute">ghbars</span> you can specify a <span class="attribute">delta</span> attribute, which
specifies the width of the bar (the default is <span class="attribute">delta=1</span>). </p>
<p class="Normal">If you say g = gcurve(), <span class="attribute">g.gcurve</span> is a curve object used to represent the gcurve.</p>
<p class="Normal">If you say g = gdots(), <span class="attribute">g.dots</span> is a points object used to represent the gdots.</p>
<p class="Normal">If you say g = gvbars(), <span class="attribute">g.vbars</span> is a faces object used to represent the vbars.</p>
<p class="Normal">If you say g = ghbars(), <span class="attribute">g.hbars</span> is a faces object used to represent the hbars.</p>
<p class="Normal"><strong><font color="#0000A0">Overall gdisplay options</font></strong></p>
<p class="Normal">You can establish a <span class="attribute">gdisplay</span> to set the size, position, and title for the title bar of the graph window,
specify titles for the x and y axes, and specify maximum values for each
axis, before creating <span class="attribute">gcurve</span> or other kind
of graph plotting object:</p>
<p class="program"> gd = gdisplay(x=0, y=0, width=600, height=150, <br />
title='N
vs. t', xtitle='t', ytitle='N', <br />
foreground=color.black,
background=color.white, <br />
xmax=50,
xmin=-20, ymax=5E3, ymin=-2E3)</p>
<p class="Normal"> In this example, the graph window will be located at (0,0),
with a size of 600 by 150 pixels, and the title bar will say 'N vs. t'.
The graph will have a title 't' on the horizontal axis and 'N' on the vertical
axis. The foreground color (white
by default) is black, and the background color (black by default) is white. </p>
<p class="Normal">Instead of autoscaling the graph to display all the data, the graph in this example
will have fixed limits. The horizontal axis will extend from -20 to +50,
and the vertical axis will extend from -200 to +5000. If you specify <span class="attribute">xmax</span> but not <span class="attribute">xmin</span>, it is as though you had also specified <span class="attribute">xmin</span> to be 0; similarly, if you specify <span class="attribute">xmin</span> but not <span class="attribute">xmax</span>, <span class="attribute">xmax</span> will be 0. The same rule holds for <span class="attribute">ymax</span> and <span class="attribute">ymin</span>.</p>
<p class="Normal"><strong>Offsets:</strong> If you specify <span class="attribute">xmin</span> or <span class="attribute">ymin</span> to be greater than zero, or <span class="attribute">xmax</span> or <span class="attribute">ymax</span> to be less than zero, the crossing point (origin) of the x and y axes will no longer be at (0,0), and the graphing will be offset. If you offset the origin of the graph, you must specify <span class="attribute">xmax</span> to be greater than <span class="attribute">xmin</span>, and/or <span class="attribute">ymax</span> to be greater than <span class="attribute">ymin</span>.</p>
<p class="Normal">If you simply say <span class="attribute">gdisplay()</span>, the defaults
are <span class="attribute">x=0</span>, <span class="attribute">y=0</span>, <span class="attribute">width=800</span>, <span class="attribute">height=400</span>,
no titles, fully autoscaled.</p>
<p class="Normal"> Every gdisplay has the attribute <span class="attribute">display</span>,
so you can place additional labels or manipulate the graphing window.
The only objects that you can place in the graphing window are labels,
curves, faces, and points.</p>
<p class="program">graph1 = gdisplay()<br />
label(display=graph1.display, pos=(3,2), text="P")<br />
graph1.display.visible = False # make the display invisible </p>
<p class="Normal">You can have more than one graph window: just create another <span class="attribute"> gdisplay</span>. By default, any graphing objects
created following a <span class="attribute">gdisplay</span> belong to that
window, or you can specify which window a new object belongs to: </p>
<p class="program"> energy = gdots(gdisplay=graph2.display, color=color.blue)</p>
<p class="Normal"><strong><font color="#0000A0">Log-log and semilog plots</font></strong></p>
<p class="Normal">When creating a gdisplay, you can specify logarithmic plots by specifying <span class="attribute">logx=True</span> and/or <span class="attribute">logy=True</span>.<strong> All values must be positive</strong>, representing logarithms of numbers between infinitely small (logarithm approaches 0) and infinitely large; that is, numbers such as 0.01, 0.1, 1, 10, 100, etc.</p>
<p class="Normal"><strong><font color="#0000A0">Histograms (sorted, binned data)</font></strong></p>
<p class="Normal">The purpose of <span class="attribute">ghistogram</span> is
to sort data into bins and display the distribution. Suppose you have a list
of the ages of a group of people, such as [5, 37, 12, 21, 8, 63, 52, 75, 7].
You want to sort these data into bins 20 years wide and display the numbers
in each bin in the form of vertical bars. The first bin (0 to 20) contains
4 people [5, 12, 8, 7], the second bin (20 to 40) contains 2 people [21, 37],
the third bin (40 to 60) contains 1 person [52], and the fourth bin (60-80)
contains 2 people [63, 75]. Here is how you could make this display:</p>
<p class="program"> from visual.graph import * <br />
.....<br />
agelist1<em class="code"> = </em>[5, 37, 12, 21, 8, 63, 52, 75, 7] <br />
ages = ghistogram(bins=arange(0,80,20), color=color.red) <br />
ages.plot(data=agelist1) # plot the age distribution<br />
.....<br />
ages.plot(data=agelist2) # plot a different distribution</p>
<p class="Normal"> You specify a list (bins) into which data will be sorted.
In the example given here, bins goes from 0 to 80 by 20's. By default, if
you later say</p>
<p class="program"> ages.plot(data=agelist2)</p>
<p class="Normal"> the new distribution replaces the old one. If on the other hand you say</p>
<p class="program"> ages.plot(data=agelist2, accumulate=True)</p>
<p class="Normal"> the new data are added to the old data. </p>
<p class="Normal"> If you say the following, </p>
<p class="program"> ghistogram(bins=arange(0,50,0.1), accumulate=True, <br />
average=True)</p>
<p class="Normal"> each plot operation will accumulate the data and average the
accumulated data. The default is no accumulation and no averaging.</p>
<p class="Normal"><strong><font color="#0000A0">gdisplay vs. display</font></strong></p>
<p class="Normal">A gdisplay window is closely related to a display window. The main difference
is that a gdisplay is essentially two-dimensional and has nonuniform x and
y scale factors. When you create a gdisplay (either explicitly, or implicitly
with the first gcurve or other graphing object), the current display is saved
and restored, so that later creation of ordinary Visual objects such as sphere
or box will correctly be associated with a previous display, not the more
recent gdisplay.</p>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td height="16" colspan="4"></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>