-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
legend.py
34 lines (25 loc) · 858 Bytes
/
legend.py
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
# -*- coding: utf-8 -*-
# https://matplotlib.org/3.2.1/gallery/text_labels_and_annotations/legend.html
import sys
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvas
from matplotlib.figure import Figure
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
fig = Figure(figsize=(8, 6))
canvas = FigureCanvas(fig)
canvas.resize(640, 480)
canvas.show()
# Make some fake data.
a = b = np.arange(0, 3, 0.02)
c = np.exp(a)
d = c[::-1]
# Create plots with pre-defined labels.
ax = fig.subplots()
ax.plot(a, c, "k--", label="Model length")
ax.plot(a, d, "k:", label="Data length")
ax.plot(a, c + d, "k", label="Total message length")
legend = ax.legend(loc="upper center", shadow=True, fontsize="x-large")
# Put a nicer background color on the legend.
legend.get_frame().set_facecolor("C0")
sys.exit(app.exec_())