datastock 0.0.35__py3-none-any.whl → 0.0.37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datastock/_class1.py +88 -127
- datastock/_class1_check.py +1 -98
- datastock/_class1_compute.py +203 -43
- datastock/_class1_domain.py +2 -2
- datastock/_class1_interpolate.py +8 -8
- datastock/_class1_show.py +406 -0
- datastock/_class1_uniformize.py +37 -19
- datastock/_class2.py +4 -48
- datastock/_class3.py +14 -6
- datastock/_generic_check.py +41 -43
- datastock/_generic_utils.py +11 -1
- datastock/_generic_utils_plot.py +76 -3
- datastock/_plot_BvsA_as_distribution_check.py +9 -5
- datastock/_plot_as_array.py +368 -2523
- datastock/_plot_as_array_1d.py +298 -0
- datastock/_plot_as_array_234d.py +786 -0
- datastock/_plot_as_mobile_lines.py +18 -13
- datastock/_plot_as_profile1d.py +27 -12
- datastock/_saveload.py +2 -0
- datastock/tests/test_01_DataStock.py +102 -27
- datastock/version.py +1 -1
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/METADATA +1 -1
- datastock-0.0.37.dist-info/RECORD +42 -0
- datastock-0.0.35.dist-info/RECORD +0 -39
- /datastock/{_plot_misc.py → _plot_old_backup.py} +0 -0
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/LICENSE +0 -0
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/WHEEL +0 -0
- {datastock-0.0.35.dist-info → datastock-0.0.37.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,298 @@
|
|
1
|
+
# coding utf-8
|
2
|
+
|
3
|
+
|
4
|
+
# Common
|
5
|
+
import numpy as np
|
6
|
+
import matplotlib.pyplot as plt
|
7
|
+
from matplotlib import gridspec
|
8
|
+
|
9
|
+
|
10
|
+
# library-specific
|
11
|
+
from . import _generic_check
|
12
|
+
from . import _plot_text
|
13
|
+
|
14
|
+
|
15
|
+
# #############################################################
|
16
|
+
# #############################################################
|
17
|
+
# Main
|
18
|
+
# #############################################################
|
19
|
+
|
20
|
+
|
21
|
+
def main(
|
22
|
+
# parameters
|
23
|
+
coll=None,
|
24
|
+
key=None,
|
25
|
+
lab=None,
|
26
|
+
dkeys=None,
|
27
|
+
ind=None,
|
28
|
+
dvminmax=None,
|
29
|
+
dscale=None,
|
30
|
+
cmap=None,
|
31
|
+
aspect=None,
|
32
|
+
nmax=None,
|
33
|
+
color_dict=None,
|
34
|
+
lkeys=None,
|
35
|
+
bstr_dict=None,
|
36
|
+
rotation=None,
|
37
|
+
# figure-specific
|
38
|
+
dax=None,
|
39
|
+
dmargin=None,
|
40
|
+
fs=None,
|
41
|
+
dcolorbar=None,
|
42
|
+
dleg=None,
|
43
|
+
label=None,
|
44
|
+
# unused
|
45
|
+
**kwdargs,
|
46
|
+
):
|
47
|
+
|
48
|
+
# --------------
|
49
|
+
# Prepare data
|
50
|
+
# --------------
|
51
|
+
|
52
|
+
data = coll.ddata[key]['data']
|
53
|
+
if hasattr(data, 'nnz'):
|
54
|
+
data = data.toarray()
|
55
|
+
assert data.ndim == len(coll.ddata[key]['ref']) == 1
|
56
|
+
n0, = data.shape
|
57
|
+
|
58
|
+
for k0, v0 in dkeys.items():
|
59
|
+
if v0['ref'] is not None:
|
60
|
+
dkeys[k0]
|
61
|
+
|
62
|
+
# --------------
|
63
|
+
# prepare figure
|
64
|
+
# --------------
|
65
|
+
|
66
|
+
if dax is None:
|
67
|
+
dax = _create_axes(
|
68
|
+
fs=fs,
|
69
|
+
dmargin=dmargin,
|
70
|
+
)
|
71
|
+
|
72
|
+
dax = _generic_check._check_dax(dax=dax, main='matrix')
|
73
|
+
|
74
|
+
# ---------------
|
75
|
+
# plot fixed part
|
76
|
+
# ---------------
|
77
|
+
|
78
|
+
axtype = 'matrix'
|
79
|
+
lkax = [kk for kk, vv in dax.items() if axtype in vv['type']]
|
80
|
+
for kax in lkax:
|
81
|
+
ax = dax[kax]['handle']
|
82
|
+
|
83
|
+
ax.plot(
|
84
|
+
coll.ddata[dkeys['X']['data']]['data'],
|
85
|
+
data,
|
86
|
+
color='k',
|
87
|
+
marker='.',
|
88
|
+
ms=6,
|
89
|
+
)
|
90
|
+
|
91
|
+
# plt.colorbar(im, ax=ax, **dcolorbar)
|
92
|
+
if dleg is not False:
|
93
|
+
ax.legend(**dleg)
|
94
|
+
|
95
|
+
# ----------------
|
96
|
+
# define and set dgroup
|
97
|
+
# ---------------
|
98
|
+
|
99
|
+
dgroup = {
|
100
|
+
'X': {
|
101
|
+
'ref': [dkeys['X']['ref']],
|
102
|
+
'data': ['index'],
|
103
|
+
'nmax': nmax,
|
104
|
+
},
|
105
|
+
}
|
106
|
+
|
107
|
+
# ----------------
|
108
|
+
# plot mobile part
|
109
|
+
# ---------------
|
110
|
+
|
111
|
+
axtype = 'matrix'
|
112
|
+
lkax = [kk for kk, vv in dax.items() if axtype in vv['type']]
|
113
|
+
for kax in lkax:
|
114
|
+
ax = dax[kax]['handle']
|
115
|
+
|
116
|
+
# ind0, ind1
|
117
|
+
for ii in range(nmax):
|
118
|
+
lv = ax.axvline(ind[0], c=color_dict['X'][ii], lw=1., ls='-')
|
119
|
+
|
120
|
+
# update coll
|
121
|
+
kv = f'{key}_v{ii:02.0f}'
|
122
|
+
coll.add_mobile(
|
123
|
+
key=kv,
|
124
|
+
handle=lv,
|
125
|
+
refs=dkeys['X']['ref'],
|
126
|
+
data=dkeys['X']['data'],
|
127
|
+
dtype='xdata',
|
128
|
+
axes=kax,
|
129
|
+
ind=ii,
|
130
|
+
)
|
131
|
+
|
132
|
+
dax[kax].update(refx=[dkeys['X']['ref']], datax=[dkeys['X']['data']])
|
133
|
+
|
134
|
+
# ---------
|
135
|
+
# add text
|
136
|
+
# ---------------
|
137
|
+
|
138
|
+
kax = 'text'
|
139
|
+
if dax.get(kax) is not None:
|
140
|
+
ax = dax[kax]['handle']
|
141
|
+
|
142
|
+
_plot_text.plot_text(
|
143
|
+
coll=coll,
|
144
|
+
kax=kax,
|
145
|
+
key=key,
|
146
|
+
ax=ax,
|
147
|
+
ref=dkeys['X']['ref'],
|
148
|
+
group='X',
|
149
|
+
ind=ind[0],
|
150
|
+
lkeys=lkeys,
|
151
|
+
nmax=nmax,
|
152
|
+
color_dict=color_dict,
|
153
|
+
bstr_dict=bstr_dict,
|
154
|
+
)
|
155
|
+
|
156
|
+
# ---------------
|
157
|
+
# labels
|
158
|
+
# ---------------
|
159
|
+
|
160
|
+
if label:
|
161
|
+
_label_axes(
|
162
|
+
coll=coll,
|
163
|
+
data_lab=lab,
|
164
|
+
dax=dax,
|
165
|
+
key=key,
|
166
|
+
dkeys=dkeys,
|
167
|
+
dvminmax=dvminmax,
|
168
|
+
rotation=rotation,
|
169
|
+
)
|
170
|
+
|
171
|
+
return coll, dax, dgroup
|
172
|
+
|
173
|
+
|
174
|
+
# #############################################################
|
175
|
+
# #############################################################
|
176
|
+
# Create axes
|
177
|
+
# #############################################################
|
178
|
+
|
179
|
+
|
180
|
+
def _create_axes(
|
181
|
+
fs=None,
|
182
|
+
dmargin=None,
|
183
|
+
):
|
184
|
+
|
185
|
+
# ---------------
|
186
|
+
# check / prepare
|
187
|
+
# ---------------
|
188
|
+
|
189
|
+
# figure size
|
190
|
+
if fs is None:
|
191
|
+
fs = (12, 8)
|
192
|
+
|
193
|
+
# dict of margins
|
194
|
+
if dmargin is None:
|
195
|
+
dmargin = {
|
196
|
+
'left': 0.05, 'right': 0.95,
|
197
|
+
'bottom': 0.10, 'top': 0.90,
|
198
|
+
'hspace': 0.15, 'wspace': 0.2,
|
199
|
+
}
|
200
|
+
|
201
|
+
# -----------------
|
202
|
+
# create
|
203
|
+
# ---------------
|
204
|
+
|
205
|
+
# figure
|
206
|
+
fig = plt.figure(figsize=fs)
|
207
|
+
|
208
|
+
# axes grid
|
209
|
+
gs = gridspec.GridSpec(ncols=4, nrows=1, **dmargin)
|
210
|
+
|
211
|
+
# axes for data
|
212
|
+
ax0 = fig.add_subplot(gs[0, :3], aspect='auto')
|
213
|
+
|
214
|
+
# axes for text
|
215
|
+
ax1 = fig.add_subplot(gs[0, 3], frameon=False)
|
216
|
+
|
217
|
+
# --------------
|
218
|
+
# assemble dax
|
219
|
+
# --------------
|
220
|
+
|
221
|
+
dax = {
|
222
|
+
'matrix': {'handle': ax0},
|
223
|
+
'text': {'handle': ax1},
|
224
|
+
}
|
225
|
+
|
226
|
+
return dax
|
227
|
+
|
228
|
+
|
229
|
+
# #############################################################
|
230
|
+
# #############################################################
|
231
|
+
# Label axes
|
232
|
+
# #############################################################
|
233
|
+
|
234
|
+
|
235
|
+
def _label_axes(
|
236
|
+
coll=None,
|
237
|
+
data_lab=None,
|
238
|
+
dax=None,
|
239
|
+
tit=None,
|
240
|
+
key=None,
|
241
|
+
dkeys=None,
|
242
|
+
dvminmax=None,
|
243
|
+
inverty=None,
|
244
|
+
rotation=None,
|
245
|
+
):
|
246
|
+
|
247
|
+
# ------
|
248
|
+
# fig
|
249
|
+
# ------
|
250
|
+
|
251
|
+
fig = list(dax.values())[0]['handle'].figure
|
252
|
+
fig.suptitle(tit, size=14, fontweight='bold')
|
253
|
+
|
254
|
+
# -------------------
|
255
|
+
# axes for data
|
256
|
+
# -------------------
|
257
|
+
|
258
|
+
axtype = 'matrix'
|
259
|
+
lax = [k0 for k0, v0 in dax.items() if axtype in v0['type']]
|
260
|
+
if len(lax) == 1:
|
261
|
+
kax = lax[0]
|
262
|
+
ax = dax[kax]['handle']
|
263
|
+
ax.set_xlabel(dkeys['X']['lab'], size=12, fontweight='bold')
|
264
|
+
ax.set_ylabel(data_lab, size=12, fontweight='bold')
|
265
|
+
|
266
|
+
if np.isfinite(dvminmax['X']['min']):
|
267
|
+
ax.set_xlim(left=dvminmax['X']['min'])
|
268
|
+
if np.isfinite(dvminmax['X']['max']):
|
269
|
+
ax.set_xlim(right=dvminmax['X']['max'])
|
270
|
+
|
271
|
+
if np.isfinite(dvminmax['data']['min']):
|
272
|
+
ax.set_ylim(bottom=dvminmax['data']['min'])
|
273
|
+
if np.isfinite(dvminmax['data']['max']):
|
274
|
+
ax.set_ylim(top=dvminmax['data']['max'])
|
275
|
+
|
276
|
+
# x text ticks
|
277
|
+
if dkeys['X']['str'] is not False:
|
278
|
+
ax.set_xticks(coll.ddata[dkeys['X']['data']]['data'])
|
279
|
+
ax.set_xticklabels(
|
280
|
+
dkeys['X']['str'],
|
281
|
+
rotation=rotation,
|
282
|
+
horizontalalignment='right',
|
283
|
+
verticalalignment='top',
|
284
|
+
)
|
285
|
+
|
286
|
+
# -------------
|
287
|
+
# axes for text
|
288
|
+
# -------------
|
289
|
+
|
290
|
+
axtype = 'text'
|
291
|
+
lax = [k0 for k0, v0 in dax.items() if axtype in v0['type']]
|
292
|
+
if len(lax) == 1:
|
293
|
+
kax = lax[0]
|
294
|
+
ax = dax[kax]['handle']
|
295
|
+
ax.set_xticks([])
|
296
|
+
ax.set_yticks([])
|
297
|
+
|
298
|
+
return dax
|