TheDoctor
TheDoctor

Reputation: 2522

Pyqtgraph horizontal bar chart

I am able to create a vertical bar chart using following code:

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

window = pg.plot()

y1 = [5, 5, 7, 10, 3, 8, 9, 1, 6, 2]
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
bargraph = pg.BarGraphItem(x=x, height=y1, width=0.6)
window.addItem(bargraph)

Result:

enter image description here

But now i need to plot a horizontal bar chart:

enter image description here

How can i do this using pyqtgraph?

Upvotes: 2

Views: 2046

Answers (1)

JoeyV120
JoeyV120

Reputation: 71

Just spin your brain 90 degrees...

Parameters:

  • x0 is the left side of the bars (zero in most cases).
  • y becomes the domain (linear series) instead of x.
  • height becomes the bar "thickness", for aesthetics.
  • width becomes the bar "length", or output values.

BarGraphItem

import pyqtgraph as pg
from pyqtgraph.Qt import QtGui

window = pg.plot()

x1 = [5, 5, 7, 10, 3, 8, 9, 1, 6, 2]
y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
bargraph = pg.BarGraphItem(x0=0, y=y, height=0.6, width=x1)
window.addItem(bargraph)
QtGui.QApplication.instance().exec_()

example horizontal bar graph

example horizontal bar graph

Upvotes: 4

Related Questions