Mercurial > repos > laurenmarazzi > netisce_test
comparison tools/myTools/bin/sfa/plot/base.py @ 1:7e5c71b2e71f draft default tip
Uploaded
author | laurenmarazzi |
---|---|
date | Wed, 22 Dec 2021 16:00:34 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:f24d4892aaed | 1:7e5c71b2e71f |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 import matplotlib.pyplot as plt | |
4 from matplotlib.gridspec import GridSpec | |
5 | |
6 | |
7 class BaseGridPlot(object): | |
8 | |
9 def __init__(self, colors=None, *args, **kwargs): | |
10 if not colors: | |
11 self._colors = dict() | |
12 else: | |
13 self._colors = dict(colors) | |
14 | |
15 self._set_colors(colors) | |
16 self._parse_kwargs(**kwargs) | |
17 | |
18 # Create figure and axis | |
19 self._create_figure() | |
20 self._create_axes() | |
21 | |
22 # end of def __init__ | |
23 | |
24 def _set_default_color(self, prop, defval): | |
25 if prop not in self._colors: | |
26 self._colors[prop] = defval | |
27 # end of def | |
28 | |
29 def _set_colors(self): | |
30 raise NotImplementedError() | |
31 | |
32 def _parse_kwargs(self, **kwargs): | |
33 """Parse the parameters for GridSpec | |
34 """ | |
35 self._dim = kwargs.get('dim', (1, 1)) | |
36 self._wspace = kwargs.get('wspace', 0) | |
37 self._hspace = kwargs.get('hspace', 0) | |
38 self._width_ratios = kwargs.get('width_ratios', [1]) | |
39 self._height_ratios = kwargs.get('height_ratios', [1]) | |
40 | |
41 def _create_figure(self): | |
42 self._fig = plt.figure() | |
43 self._gridspec = GridSpec(*self._dim, | |
44 wspace=self._wspace, | |
45 hspace=self._hspace, | |
46 width_ratios=self._width_ratios, | |
47 height_ratios=self._height_ratios) | |
48 | |
49 self._fig.set_facecolor('white') | |
50 | |
51 def _create_axes(self): | |
52 self._axes = {} | |
53 ax = self._fig.add_subplot(self._gridspec[0, 0]) | |
54 self._axes['base'] = ax | |
55 ax.grid(b=False) | |
56 ax.set_frame_on(False) | |
57 ax.invert_yaxis() | |
58 ax.xaxis.tick_top() | |
59 | |
60 @property | |
61 def column_tick_fontsize(self): | |
62 return self._column_tick_fontsize | |
63 | |
64 @column_tick_fontsize.setter | |
65 def column_tick_fontsize(self, val): | |
66 self._column_tick_fontsize = val | |
67 for ax in self._axes.values(): | |
68 ax.tick_params(axis='x', which='major', | |
69 labelsize=self._column_tick_fontsize) | |
70 | |
71 @property | |
72 def row_tick_fontsize(self): | |
73 return self._row_tick_fontsize | |
74 | |
75 @row_tick_fontsize.setter | |
76 def row_tick_fontsize(self, val): | |
77 self._row_tick_fontsize = val | |
78 for ax in self._axes.values(): | |
79 ax.tick_params(axis='y', which='major', | |
80 labelsize=self._row_tick_fontsize) | |
81 | |
82 # # Properties | |
83 # @property | |
84 # def column_tick_fontsize(self): | |
85 # raise NotImplementedError() | |
86 # | |
87 # @column_tick_fontsize.setter | |
88 # def column_tick_fontsize(self, val): | |
89 # raise NotImplementedError() | |
90 # | |
91 # @property | |
92 # def row_tick_fontsize(self): | |
93 # raise NotImplementedError() | |
94 # | |
95 # @row_tick_fontsize.setter | |
96 # def row_tick_fontsize(self, val): | |
97 # raise NotImplementedError() | |
98 | |
99 # @property | |
100 # def text_fontsize(self): | |
101 # raise NotImplementedError() | |
102 # | |
103 # @text_fontsize.setter | |
104 # def text_fontsize(self, val): | |
105 # raise NotImplementedError() | |
106 # | |
107 # @property | |
108 # def linewidth(self): | |
109 # raise NotImplementedError() | |
110 # | |
111 # @linewidth.setter | |
112 # def linewidth(self, val): | |
113 # raise NotImplementedError() | |
114 | |
115 # Read-only properties | |
116 @property | |
117 def colors(self): | |
118 return self._colors | |
119 | |
120 @property | |
121 def fig(self): | |
122 return self._fig | |
123 | |
124 @property | |
125 def axes(self): | |
126 return self._axes | |
127 | |
128 @property | |
129 def gridspec(self): | |
130 return self._gridspec | |
131 | |
132 | |
133 class BaseTable(BaseGridPlot): | |
134 | |
135 def __init__(self, *args, **kwargs): | |
136 super().__init__(*args, **kwargs) | |
137 self._create_tables() | |
138 | |
139 def _create_tables(self): | |
140 raise NotImplementedError() | |
141 | |
142 @property | |
143 def tables(self): | |
144 return self._tables |