Matplotlib库中的stackplot函数的使用方法如下:
import matplotlib.pyplot as plt
import numpy as np
import numpy.random as npr
x = np.linspace(0,10,50)
y = [npr.rand(50) for i in range(4)]
plt.stackplot(x,y)
plt.show()我需要为一个项目使用PyQtGraph库:
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
import numpy as np
import numpy.random as npr
x = np.linspace(0,10,50)
y = [npr.rand(50) for i in range(4)]
win = pg.GraphicsWindow()
graph = win.addPlot()
#stackplot function
QtGui.QApplication.instance().exec_()怎样才能得到堆积图?
发布于 2020-04-22 06:11:33
Pyqtgraph没有内置的堆叠图功能,但你可以自己编写,只需在堆叠每一行之前汇总绘图数据,并使用PlotCurveItem的fillLevel和fillBrush参数。示例:
import pyqtgraph as pg
import numpy as np
data = np.random.normal(size=(7,10), scale=0.1, loc=1)
stacked = np.cumsum(data, axis=0)
plt = pg.plot()
for i,row in enumerate(stacked):
curve = plt.plot(row, fillLevel=0, fillBrush=(i,10))
curve.setZValue(10-i)https://stackoverflow.com/questions/61262105
复制相似问题