-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli-examples.ht
126 lines (117 loc) · 3.95 KB
/
cli-examples.ht
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
Title: Command Line Interpreter Examples
<h1>PyQwt Command Line Interpreter Examples</h1>
<p>The programming style imposed by PyQt (and other GUI toolkit wrappers) is to
create an application instance with some widgets and to enter into an event
loop that locks you from the Python command line interpreter or an enhanced
interpreter like <a href="http://ipython.scipy.org">IPython</a>.
</p>
<p>PyQwt includes the <tt class="module">iqt</tt> module that allows to:
</p>
<ul>
<li>create and control (Py)Qt widgets from the command line interpreter.</li>
<li>interact with those widgets through (Py)Qt's GUI.</li>
</ul>
<p>Note: on Windows, the iqt module requires at least PyQwt-5.0.1 or
PyQwt-4.2.3.
</p>
<p>A step by step example follows:
</p>
<ol>
<li>
Start <b class="program">python</b> (or <b class="program">ipython</b>)
and type:
<pre class="cli">
>>> import PyQt4.Qwt5.iqt
</pre>
to create an application instance and to simulate entering an event loop
which does not inhibit the Python interpreter to read its input.
</li>
<li>
The module <tt class="module">qwt.qplt</tt> provides an interpreter
friendly interface to the QwtPlot class. Type:
<pre class="cli">
>>> from PyQt4.Qwt5.qplt import *
</pre>
to load the classes <tt class="class">Plot</tt>,
<tt class="class">IPlot</tt>, <tt class="class"> Curve</tt>,
<tt class="class">Axis</tt>, <tt class="class">Pen</tt> and
<tt class="class">Symbol</tt>.
</li>
<li>
Type:
<pre class="cli">
>>> x = np.arange(-2*np.pi, 2*np.pi, 0.01)
</pre>
to create an array of x-values, ranging from -2*pi to 2*pi with a step size
of 0.01.
</li>
<li>
Type:
<pre class="cli">
>>> p = Plot(Curve(x, np.cos(x), Pen(Magenta, 2), "cos(x)"),
... Curve(x, np.exp(x), Pen(Red), "exp(x)", Y2),
... Axis(Right, Log),
... "PyQwt using Qwt-%s -- http://qwt.sf.net" % QWT_VERSION_STR)
</pre>
to show a plot with two curves, a linear x-axis, a linear y-axis, a
logarithmic y-axis and a title.
<p><img alt="plot with two curves" src="examples/CliDemo0.png"
width=600 height=400 border=1></p>
A <tt class="class">Plot</tt> widget has hidden features:
<ul>
<li>
toggle the visibility of each curve by clicking on its legend item.
</li>
<li>
zooming and unzooming uses an infinite deep stack:
<ul>
<li>left-click&drag&release to zoom</li>
<li>right-click to unzoom to the previous zoom selection</li>
<li>middle-click to unzoom to the initial state</li>
</ul>
</li>
</ul>
</li>
<li>
There is also an <tt class="class">IPlot</tt> widget that adds a few
interactive buttons to <tt class="class">Plot</tt> to facilitate printing
to a printer or an (E)PS file and to clone the plot into Grace.
Grace is an interactive plotting program producing hardcopy output that
is better suited for LaTeX documents and scientific journals.
Type:
<pre class="cli">
>>> p = IPlot(Curve(x, np.cos(x), Pen(Magenta, 2), "cos(x)"),
... Curve(x, np.exp(x), Pen(Red), "exp(x)", Y2),
... Axis(Right, Log),
... "PyQwt using Qwt-%s -- http://qwt.sf.net" % QWT_VERSION_STR)
</pre>
to show it.
</li>
<li>
Type:
<pre class="cli">
>>> x = x[0:-1:10]
</pre>
to create a new array of x-values by selecting every 10th element of the
old array.
</li>
<li>
Type:
<pre class="cli">
>>> p.plot(Curve(x, np.cos(x-np.pi/4), Symbol(Circle, Yellow), "circle"),
... Curve(x, np.cos(x+np.pi/4), Pen(Blue), Symbol(Square, Cyan), "square"))
</pre>
to add two more curves to the plot.
<p><img alt="plot with four curves" src="examples/CliDemo1.png"
width=700 height=500 border=1></p>
</li>
</ol>
<p>
See the <a href="doc5/qwt-qplt.html">PyQt4.Qwt5.qplt documentation</a>
for detailed information.
</p>
<!--
Local Variables:
mode: HTML
End:
-->