Reputation: 2522
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:
But now i need to plot a horizontal bar chart:
How can i do this using pyqtgraph
?
Upvotes: 2
Views: 2046
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.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
Upvotes: 4