from
PyQt5.QtWidgets
import
*
import
sys
import
numpy as np
import
pyqtgraph as pg
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
pyqtgraph.ptime as ptime
class
ImageView(pg.ImageView):
def
__init__(
self
,
*
args,
*
*
kwargs):
pg.ImageView.__init__(
self
,
*
args,
*
*
kwargs)
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle(
"PyQtGraph"
)
self
.setGeometry(
100
,
100
,
600
,
500
)
icon
=
QIcon(
"skin.png"
)
self
.setWindowIcon(icon)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
widget
=
QWidget()
label
=
QLabel(
"Geeksforgeeks Graph Item"
)
label.setMinimumWidth(
130
)
label.setWordWrap(
True
)
pg.setConfigOptions(antialias
=
True
)
win
=
pg.GraphicsLayoutWidget()
view
=
win.addViewBox()
view.setAspectLocked()
graph_item
=
pg.GraphItem()
view.addItem(graph_item)
pos
=
np.array([
[
0
,
0
],
[
10
,
0
],
[
0
,
10
],
[
10
,
10
],
[
5
,
5
],
[
15
,
5
]
])
adj
=
np.array([
[
0
,
1
],
[
1
,
3
],
[
3
,
2
],
[
2
,
0
],
[
1
,
5
],
[
3
,
5
],
])
symbols
=
[
'o'
,
'x'
,
'o'
,
'o'
,
't'
,
'+'
]
graph_item.setData(pos
=
pos, adj
=
adj, size
=
1
, symbol
=
symbols, pxMode
=
False
)
layout
=
QGridLayout()
label.setMinimumWidth(
130
)
widget.setLayout(layout)
layout.addWidget(label,
1
,
0
)
layout.addWidget(win,
0
,
1
,
3
,
1
)
self
.setCentralWidget(widget)
lines_pen
=
np.array([
(
255
,
0
,
150
,
255
,
10
),
(
255
,
0
,
255
,
255
,
2
),
(
255
,
0
,
255
,
255
,
3
),
(
255
,
255
,
0
,
255
,
2
),
(
255
,
0
,
50
,
255
,
1
),
(
255
,
255
,
255
,
255
,
4
),
], dtype
=
[(
'red'
, np.ubyte), (
'green'
, np.ubyte), (
'blue'
, np.ubyte), (
'alpha'
, np.ubyte), (
'width'
,
float
)])
graph_item.setPen(lines_pen)
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())