Question

The pyqtgraph examples include how to histogram with the variable along the x-axis and the counts along the y-axis, as shown below. Is there a way to have the variable run along the y-axis and the counts along the x-axis, with fillLevel filling to the y-axis?

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)
Était-ce utile?

La solution

PlotCurveItem will always fill to a line that is horizontal within its own coordinate system. So if you want it to fill to the y-axis, it must be rotated:

curve.rotate(90)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top