-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathplot_utils.py
More file actions
53 lines (38 loc) · 1.12 KB
/
plot_utils.py
File metadata and controls
53 lines (38 loc) · 1.12 KB
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
import os
import matplotlib.pyplot as plt
from dataclasses import dataclass
def savefig_to_path(fig, path):
fig.savefig(path + ".png")
fig.savefig(path + ".svg")
PLOT_PATH = f"{os.path.realpath(os.path.dirname(__file__))}/../plots"
def get_plot_path(name):
return f"{PLOT_PATH}/{name}"
@dataclass
class PlotDefinition:
"""Plot definition"""
path: str
title: str
xlabel: str
ylabel: str
miny: int
maxy: int
minx: int
maxx: int
@dataclass
class SubplotDefinition:
"""A target for plotting"""
label: str
color: str
class GenericPlot:
def __init__(self, plotdefinition):
self.plotdefinition = plotdefinition
self.fig, self.ax = plt.subplots()
plt.xlabel(self.plotdefinition.xlabel)
plt.ylabel(self.plotdefinition.ylabel)
plt.title(self.plotdefinition.title)
self.ax.grid(True)
def save_to_disk(self):
plt.xlim(self.plotdefinition.minx, self.plotdefinition.maxx)
plt.ylim(self.plotdefinition.miny, self.plotdefinition.maxy)
plt.legend()
savefig_to_path(plt, self.plotdefinition.path)