-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaxes.py
More file actions
101 lines (70 loc) · 2.88 KB
/
Copy pathaxes.py
File metadata and controls
101 lines (70 loc) · 2.88 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
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
98
99
100
101
from abc import ABC, abstractmethod
import numpy as np
from matplotlib.axes import Axes
from matplotlib.ticker import FormatStrFormatter
class Axis(ABC):
def __init__(self, axes: Axes):
self._axes = axes
@property
def axes(self) -> Axes:
return self._axes
@abstractmethod
def add_title(self, title: str):
pass
@abstractmethod
def scale(self, lower_limit: float, upper_limit: float, step: float):
pass
@abstractmethod
def format_ticks(self, fmt: str = '%.2f'):
pass
class X1Axis(Axis):
def add_title(self, title: str):
self._axes.set_xlabel(title)
def scale(self, lower_limit: float, upper_limit: float, step: float):
ticks = np.arange(lower_limit, upper_limit + step, step)
self._axes.set_xticks(ticks)
self._axes.set_xlim(ticks[0], ticks[-1])
def format_ticks(self, fmt: str = '%.2f'):
self._axes.xaxis.set_major_formatter(FormatStrFormatter(fmt))
class Y1Axis(Axis):
def add_title(self, title: str):
self._axes.set_ylabel(title)
def scale(self, lower_limit: float, upper_limit: float, step: float):
ticks = np.arange(lower_limit, upper_limit + step, step)
self._axes.set_yticks(ticks)
self._axes.set_ylim(ticks[0], ticks[-1])
def format_ticks(self, fmt: str = '%.2f'):
self._axes.yaxis.set_major_formatter(FormatStrFormatter(fmt))
class X2Axis(Axis):
def __init__(self, axes: Axes):
super().__init__(axes)
self._twin_axes = axes.twiny()
self._twin_axes.xaxis.set_ticks_position('bottom')
self._twin_axes.xaxis.set_label_position('bottom')
self._twin_axes.spines['bottom'].set_position(('outward', 40))
@property
def axes(self) -> Axes:
return self._twin_axes
def add_title(self, title: str):
self._twin_axes.set_xlabel(title)
def scale(self, lower_limit: float, upper_limit: float, step: float):
ticks = np.arange(lower_limit, upper_limit, step)
self._twin_axes.set_xticks(ticks)
self._twin_axes.set_xlim(ticks[0], ticks[-1])
def format_ticks(self, fmt: str = '%.2f'):
self._twin_axes.xaxis.set_major_formatter(FormatStrFormatter(fmt))
class Y2Axis(Axis):
def __init__(self, axes: Axes):
super().__init__(axes)
self._twin_axes = axes.twinx()
@property
def axes(self) -> Axes:
return self._twin_axes
def add_title(self, title: str):
self._twin_axes.set_ylabel(title)
def scale(self, lower_limit: float, upper_limit: float, step: float):
ticks = np.arange(lower_limit, upper_limit, step)
self._twin_axes.set_yticks(ticks)
self._twin_axes.set_ylim(ticks[0], ticks[-1])
def format_ticks(self, fmt: str = '%.2f'):
self._twin_axes.yaxis.set_major_formatter(FormatStrFormatter(fmt))