Skip to content

Commit 57a27c6

Browse files
committed
Curve plotting: added support for numpy.float32 data type
1 parent e5437af commit 57a27c6

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# PythonQwt Releases
22

3+
## Version 0.9.2
4+
5+
- Curve plotting: added support for `numpy.float32` data type.
6+
37
## Version 0.9.1
48

5-
- Added load test showing a large number of plots (eventually highlights performance issues)
9+
- Added load test showing a large number of plots (eventually highlights performance issues).
610
- Fixed event management in `QwtPlot` and removed unnecessary `QEvent.LayoutRequest`
7-
emission in `QwtScaleWidget` (caused high CPU usage with `guiqwt.ImageWidget`)
8-
- `QwtScaleDiv`: fixed ticks initialization when passing all arguments to constructor
9-
- tests/image.py: fixed overriden `updateLegend` signature
11+
emission in `QwtScaleWidget` (caused high CPU usage with `guiqwt.ImageWidget`).
12+
- `QwtScaleDiv`: fixed ticks initialization when passing all arguments to constructor.
13+
- tests/image.py: fixed overriden `updateLegend` signature.
1014

1115
## Version 0.9.0
1216

qwt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
.. _GitHubPage: http://pierreraybaut.github.io/PythonQwt
2929
.. _GitHub: https://github.com/PierreRaybaut/PythonQwt
3030
"""
31-
__version__ = "0.9.1"
31+
__version__ = "0.9.2"
3232
QWT_VERSION_STR = "6.1.5"
3333

3434
import warnings

qwt/plot_curve.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,30 @@ def qwtVerifyRange(size, i1, i2):
6262

6363
def array2d_to_qpolygonf(xdata, ydata):
6464
"""
65-
Utility function to convert two 1D-NumPy arrays representing curve data
66-
(X-axis, Y-axis data) into a single polyline (QtGui.PolygonF object).
65+
Utility function to convert two 1D-NumPy arrays representing curve data
66+
(X-axis, Y-axis data) into a single polyline (QtGui.PolygonF object).
6767
This feature is compatible with PyQt4, PyQt5 and PySide2 (requires QtPy).
68-
69-
License/copyright: MIT License © Pierre Raybaut 2020.
70-
71-
:param numpy.ndarray xdata: 1D-NumPy array (numpy.float64)
72-
:param numpy.ndarray ydata: 1D-NumPy array (numpy.float64)
68+
69+
License/copyright: MIT License © Pierre Raybaut 2020-2021.
70+
71+
:param numpy.ndarray xdata: 1D-NumPy array
72+
:param numpy.ndarray ydata: 1D-NumPy array
7373
:return: Polyline
7474
:rtype: QtGui.QPolygonF
7575
"""
76-
dtype = np.float64
77-
if not (
78-
xdata.size == ydata.size == xdata.shape[0] == ydata.shape[0]
79-
and xdata.dtype == ydata.dtype == dtype
80-
):
81-
raise ValueError("Arguments must be 1D, float64 NumPy arrays with same size")
76+
if not (xdata.size == ydata.size == xdata.shape[0] == ydata.shape[0]):
77+
raise ValueError("Arguments must be 1D NumPy arrays with same size")
8278
size = xdata.size
8379
polyline = QPolygonF(size)
8480
if PYSIDE2: # PySide2 (obviously...)
8581
address = shiboken2.getCppPointer(polyline.data())[0]
8682
buffer = (ctypes.c_double * 2 * size).from_address(address)
8783
else: # PyQt4, PyQt5
8884
buffer = polyline.data()
89-
buffer.setsize(2 * size * np.finfo(dtype).dtype.itemsize)
90-
memory = np.frombuffer(buffer, dtype)
91-
memory[: (size - 1) * 2 + 1 : 2] = xdata
92-
memory[1 : (size - 1) * 2 + 2 : 2] = ydata
85+
buffer.setsize(16 * size) # 16 bytes per point: 8 bytes per X,Y value (float64)
86+
memory = np.frombuffer(buffer, np.float64)
87+
memory[: (size - 1) * 2 + 1 : 2] = np.array(xdata, dtype=np.float64, copy=False)
88+
memory[1 : (size - 1) * 2 + 2 : 2] = np.array(ydata, dtype=np.float64, copy=False)
9389
return polyline
9490

9591

0 commit comments

Comments
 (0)