1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| from matplotlib.backends.backend_qt5agg import (FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
from matplotlib.figure import Figure
import numpy as np
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QMainWindow, QApplication
import sys
from PyQt5.QtCore import Qt
import datetime
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.labels = ["Label1", "Label2", "Label3", "Label4",
"Label5", "Label6", "Label7", "Label8"]
self.values = [100, 70, 60, 50,
70, 40, 100, 60]
self.widget_1 = QWidget()
self.widget_2 = QWidget()
self.widget_3 = QWidget()
self.widget_4 = QWidget()
self.widget_5 = QWidget()
self.widget_6 = QWidget()
self.widget_7 = QWidget()
self.widget_8 = QWidget()
nb_val = len(self.labels)
self.theta = np.linspace(0, 2*np.pi, nb_val, endpoint=False).tolist()
self.figure_radar = FigureCanvas(Figure())
self.graphique_radar = self.figure_radar.figure.subplots(nrows=1, ncols=1, subplot_kw=dict(projection='polar'))
self.figure_radar.figure.canvas.mpl_connect("motion_notify_event", self.hover)
self.figure_radar.figure.canvas.mpl_connect("pick_event", self.on_pick)
self.instance_graphique = self.graphique_radar.bar(self.theta, self.values, color=["blue", "red", "green", "pink","violet","black","brown","yellow"], alpha = 0.45, width=0.55, picker = True)
self.annotations = self.graphique_radar.annotate("", xy=(0,0), xytext=(-20,20), textcoords="offset points", bbox=dict(boxstyle="round", fc="black", ec="b", lw=2), arrowprops=dict(arrowstyle="->"))
self.annotations.set_visible(False)
self.graphique_radar.set_thetagrids(np.degrees(self.theta))
self.graphique_radar.set_xticklabels(self.labels)
self.graphique_radar.set_yticklabels([])
self.graphique_radar.set_title("Indicateur X\n" + "Mise à jour: " + str(datetime.datetime.today().strftime("%d/%m/%Y %H:%M:%S")) + "\n")
self.graphique_radar.tick_params(pad=20)
self.graphique_radar.set_ylim(0, 100)
self.figure_radar.figure.tight_layout()
self.figure_radar.figure.savefig("test.jpg")
self.setCentralWidget(QWidget(parent=self))
self.layout_vertical = QVBoxLayout(self.centralWidget())
self.layout_vertical.addWidget(self.figure_radar)
def on_pick(self, evt):
ind = self.instance_graphique.index(evt.artist)
if self.labels[ind]== "Label1":
self.widget_1.show()
print("Label1")
elif self.labels[ind]== "Label2":
self.widget_2.show()
print("Label2")
elif self.labels[ind]== "Label3":
self.widget_3.show()
print("Label3")
elif self.labels[ind]== "Label4":
self.widget_4.show()
print("Label4")
elif self.labels[ind]== "Label5":
self.widget_5.show()
print("Label5")
elif self.labels[ind]== "Label6":
self.widget_6.show()
print("Label6")
elif self.labels[ind]== "Label7":
self.widget_7.show()
print("Label7")
elif self.labels[ind]== "Label8":
self.widget_8 = QWidget()
print("Label8")
def hover(self, event):
if event.inaxes == self.graphique_radar:
self.graphique_radar.set_alpha(0.45)
for bar in self.instance_graphique:
cont, ind = bar.contains(event)
if cont:
bar.set_alpha(1)
QApplication.setOverrideCursor(Qt.PointingHandCursor)
break
else:
bar.set_alpha(0.45)
QApplication.setOverrideCursor(Qt.ArrowCursor)
self.figure_radar.draw_idle()
if __name__ == "__main__":
appli = QApplication(sys.argv)
fenetre_main = MainWindow()
fenetre_main.show()
sys.exit(appli.exec_()) |
Partager