1# -*- coding: utf-8 -*-
2"""
3Simple example using BarGraphItem
4"""
5import initExample ## Add path to library (just for examples; you do not need this)
6
7import pyqtgraph as pg
8from pyqtgraph.Qt import QtCore, QtGui
9import numpy as np
10
11win = pg.plot()
12win.setWindowTitle('pyqtgraph example: BarGraphItem')
13
14x = np.arange(10)
15y1 = np.sin(x)
16y2 = 1.1 * np.sin(x+1)
17y3 = 1.2 * np.sin(x+2)
18
19bg1 = pg.BarGraphItem(x=x, height=y1, width=0.3, brush='r')
20bg2 = pg.BarGraphItem(x=x+0.33, height=y2, width=0.3, brush='g')
21bg3 = pg.BarGraphItem(x=x+0.66, height=y3, width=0.3, brush='b')
22
23win.addItem(bg1)
24win.addItem(bg2)
25win.addItem(bg3)
26
27
28# Final example shows how to handle mouse clicks:
29class BarGraph(pg.BarGraphItem):
30    def mouseClickEvent(self, event):
31        print("clicked")
32
33
34bg = BarGraph(x=x, y=y1*0.3+2, height=0.4+y1*0.2, width=0.8)
35win.addItem(bg)
36
37if __name__ == '__main__':
38    pg.exec()
39