在pyqtgraph中沿y轴计数的直方图?

时间:2013-09-19 13:27:37

标签: pyqtgraph

pyqtgraph示例包括如何使用沿x轴的变量和沿y轴的计数进行直方图,如下所示。有没有办法让变量沿y轴运行,沿x轴计数,fillLevel填充到y轴?

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np

win = pg.GraphicsWindow()
win.resize(800,350)
win.setWindowTitle('pyqtgraph example: Histogram')
plt1 = win.addPlot()

## make interesting distribution of values
vals = np.hstack([np.random.normal(size=500), np.random.normal(size=260, loc=4)])

## compute standard histogram
y,x = np.histogram(vals, bins=np.linspace(-3, 8, 40))

## notice that len(x) == len(y)+1
## We are required to use stepMode=True so that PlotCurveItem will interpret this data correctly.
curve = pg.PlotCurveItem(x, y, stepMode=True, fillLevel=0, brush=(0, 0, 255, 80))
plt1.addItem(curve)

1 个答案:

答案 0 :(得分:4)

PlotCurveItem将始终填充到其自己的坐标系中水平的线。因此,如果您希望它填充到y轴,则必须旋转它:

curve.rotate(90)