Skip to content

Commit c3dba2b

Browse files
committed
Updated simple example (added to README.md)
1 parent b3a3d8e commit c3dba2b

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ From the source package:
7979
python setup.py install
8080
```
8181

82-
## Examples/tests
82+
## Examples (tests)
8383

8484
The GUI-based test launcher may be executed from Python:
8585

@@ -93,3 +93,21 @@ or from the command line:
9393
```bash
9494
PythonQwt-tests
9595
```
96+
97+
## Sample
98+
99+
```python
100+
import qwt
101+
import numpy as np
102+
103+
app = qwt.qt.QtGui.QApplication([])
104+
x = np.linspace(-10, 10, 500)
105+
plot = qwt.QwtPlot("Trigonometric functions")
106+
plot.insertLegend(qwt.QwtLegend(), qwt.QwtPlot.BottomLegend)
107+
qwt.QwtPlotCurve.make(x, np.cos(x), "Cosinus", plot, linecolor="red", antialiased=True)
108+
qwt.QwtPlotCurve.make(x, np.sin(x), "Sinus", plot, linecolor="blue", antialiased=True)
109+
plot.resize(600, 300)
110+
plot.show()
111+
```
112+
113+
<img src="https://raw.githubusercontent.com/PierreRaybaut/PythonQwt/master/doc/images/QwtPlot_example.png">

doc/images/QwtPlot_example.png

22 KB
Loading

doc/plot_example.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
from qwt.qt.QtGui import QApplication
2-
from qwt import QwtPlot, QwtPlotCurve
1+
import qwt
32
import numpy as np
4-
import os.path as osp
5-
6-
app = QApplication([])
73

4+
app = qwt.qt.QtGui.QApplication([])
85
x = np.linspace(-10, 10, 500)
9-
y1, y2 = np.cos(x), np.sin(x)
6+
plot = qwt.QwtPlot("Trigonometric functions")
7+
plot.insertLegend(qwt.QwtLegend(), qwt.QwtPlot.BottomLegend)
8+
qwt.QwtPlotCurve.make(x, np.cos(x), "Cosinus", plot, linecolor="red", antialiased=True)
9+
qwt.QwtPlotCurve.make(x, np.sin(x), "Sinus", plot, linecolor="blue", antialiased=True)
10+
plot.resize(600, 300)
11+
plot.show()
1012

11-
my_plot = QwtPlot("Two curves")
12-
curve1, curve2 = QwtPlotCurve("Curve 1"), QwtPlotCurve("Curve 2")
13-
curve1.setData(x, y1)
14-
curve2.setData(x, y2)
15-
curve1.attach(my_plot)
16-
curve2.attach(my_plot)
17-
my_plot.resize(600, 300)
18-
my_plot.replot()
19-
my_plot.show()
13+
import os.path as osp
2014

21-
my_plot.grab().save(
15+
plot.grab().save(
2216
osp.join(osp.abspath(osp.dirname(__file__)), "images", "QwtPlot_example.png")
2317
)
2418

qwt/plot.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,17 @@ class QwtPlot(QFrame, QwtPlotDict):
239239
The following example is a good starting point to see how to set up a
240240
plot widget::
241241
242-
from .qt.QtGui import QApplication
243-
from qwt import QwtPlot, QwtPlotCurve
242+
import qwt
244243
import numpy as np
245244
246-
app = QApplication([])
247-
245+
app = qwt.qt.QtGui.QApplication([])
248246
x = np.linspace(-10, 10, 500)
249-
y1, y2 = np.cos(x), np.sin(x)
250-
251-
my_plot = QwtPlot("Two curves")
252-
curve1, curve2 = QwtPlotCurve("Curve 1"), QwtPlotCurve("Curve 2")
253-
curve1.setData(x, y1)
254-
curve2.setData(x, y2)
255-
curve1.attach(my_plot)
256-
curve2.attach(my_plot)
257-
my_plot.resize(600, 300)
258-
my_plot.replot()
259-
my_plot.show()
260-
261-
app.exec_()
247+
plot = qwt.QwtPlot("Trigonometric functions")
248+
plot.insertLegend(qwt.QwtLegend(), qwt.QwtPlot.BottomLegend)
249+
qwt.QwtPlotCurve.make(x, np.cos(x), "Cosinus", plot, linecolor="red", antialiased=True)
250+
qwt.QwtPlotCurve.make(x, np.sin(x), "Sinus", plot, linecolor="blue", antialiased=True)
251+
plot.resize(600, 300)
252+
plot.show()
262253
263254
.. image:: /images/QwtPlot_example.png
264255

0 commit comments

Comments
 (0)