问题描述
目前我正在使用 matplotlib
绘制多个 numpy
数据数组(或列表).这些对应于大约 3000 个图.这些图是时间序列.我的问题是,当这些列表因数据过多而变得太大时,matplotlib 会非常慢.我读到 pyqtgraph
的绘图速度非常快,但我的问题是:
At the moment I am using matplotlib
to plot multiple numpy
arrays (or lists) of data. These correspond to approximately 3000 plots. The plots are time series.My problem is that when these lists become too large with a lot of data, matplotlib is very slow. I read that pyqtgraph
can plot really fast, but my question is:
您能否使用 pyqtgraph 绘制数据而不生成 pyqt
窗口,而是直接将它们保存到文件中?Matplotlib 有一个更改后端的选项,因此它不会生成窗口,而只是创建文件,pyqtgraph 是否有类似的东西?
Can you use pyqtgraph to plot data without spawning that pyqt
window and instead directly save them to files? Matplotlib had an option to change backend so it does not spawn the window but instead just create the file, is there something similar for pyqtgraph?
你还认为,对于我的问题,pyqtgraph 是正确的方法吗?我看到很多实时绘制流数据,但我想做的不涉及实时流数据.我应该使用其他方法为我的所有数据创建图表吗?
Also do you think that, for my problem, pyqtgraph is the correct way to go? I see it a lot for plotting streaming data live, but what I want to do does not involve live stream data. Should I use something else to create plots for all my data?
推荐答案
如果要保存绘图的图像,则不需要显示窗口,示例如下:
You do not need to show a window if you want to save an image of the plot, the following in an example:
import pyqtgraph as pg
import pyqtgraph.exporters
plt = pg.plot([1, 2, 3, 4, 5], [2, 5, 2, 5, 2])
exporter = pg.exporters.ImageExporter(plt.plotItem)
exporter.parameters()['width'] = 640
exporter.export('fileName.png')
虽然那个库有bug,但解决方法很简单,你必须去文件pyqtgraph/exporters/ImageExporter.py
Although that library has a bug, the solution is simple, you must go to the file pyqtgraph/exporters/ImageExporter.py
pyqtgraph
|
...
├── exporters
│ ├── ...
│ ├── ImageExporter.py
... ...
并更改第 70 行:
bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte)
到:
bg = np.empty((int(self.params['width']), int(self.params['height']), 4), dtype=np.ubyte)
fileName.png
参考:
这篇关于pyqtgraph 用于绘制多个数据列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!