【问题标题】:Histogram with counts along y axis in pyqtgraph?在pyqtgraph中沿y轴计数的直方图?
【发布时间】:2013-09-24 14:44:00
【问题描述】:

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)

【问题讨论】:

    标签: pyqtgraph


    【解决方案1】:

    PlotCurveItem 将始终填充到其自身坐标系内的水平线。所以如果你想让它填充到 y 轴,它必须旋转:

    curve.rotate(90)
    

    【讨论】:

    • 要沿正 y 轴计数,我做了curve = pg.PlotCurveItem(-1.*x, y, stepMode=True, fillLevel=0, brush=(0, 0, 255, 80)),然后是curve.rotate(-90)。谢谢!
    猜你喜欢
    • 2017-10-24
    • 1970-01-01
    • 2017-07-30
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    相关资源
    最近更新 更多