ZTWHHH commited on
Commit
85b1e75
·
verified ·
1 Parent(s): a0b1550

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/__init__.py +14 -0
  2. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/angle_helper.py +394 -0
  3. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axes_divider.py +2 -0
  4. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axis_artist.py +1115 -0
  5. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axisline_style.py +193 -0
  6. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axislines.py +479 -0
  7. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/floating_axes.py +275 -0
  8. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/grid_finder.py +326 -0
  9. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.py +328 -0
  10. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/parasite_axes.py +7 -0
  11. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/__init__.py +10 -0
  12. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/test_axis_artist.py +99 -0
  13. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/test_axislines.py +147 -0
  14. vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/test_grid_finder.py +34 -0
  15. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/__init__.cpython-310.pyc +0 -0
  16. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/_locale_data.cpython-310.pyc +0 -0
  17. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/auth.cpython-310.pyc +0 -0
  18. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/autoreload.cpython-310.pyc +0 -0
  19. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/concurrent.cpython-310.pyc +0 -0
  20. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/curl_httpclient.cpython-310.pyc +0 -0
  21. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/escape.cpython-310.pyc +0 -0
  22. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/gen.cpython-310.pyc +0 -0
  23. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/http1connection.cpython-310.pyc +0 -0
  24. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/httpclient.cpython-310.pyc +0 -0
  25. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/httpserver.cpython-310.pyc +0 -0
  26. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/httputil.cpython-310.pyc +0 -0
  27. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/ioloop.cpython-310.pyc +0 -0
  28. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/iostream.cpython-310.pyc +0 -0
  29. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/locale.cpython-310.pyc +0 -0
  30. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/locks.cpython-310.pyc +0 -0
  31. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/log.cpython-310.pyc +0 -0
  32. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/netutil.cpython-310.pyc +0 -0
  33. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/options.cpython-310.pyc +0 -0
  34. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/process.cpython-310.pyc +0 -0
  35. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/queues.cpython-310.pyc +0 -0
  36. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/routing.cpython-310.pyc +0 -0
  37. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/simple_httpclient.cpython-310.pyc +0 -0
  38. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/tcpclient.cpython-310.pyc +0 -0
  39. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/tcpserver.cpython-310.pyc +0 -0
  40. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/template.cpython-310.pyc +0 -0
  41. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/testing.cpython-310.pyc +0 -0
  42. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/util.cpython-310.pyc +0 -0
  43. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/websocket.cpython-310.pyc +0 -0
  44. vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/wsgi.cpython-310.pyc +0 -0
  45. vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/__init__.cpython-310.pyc +0 -0
  46. vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/asyncio_test.cpython-310.pyc +0 -0
  47. vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/autoreload_test.cpython-310.pyc +0 -0
  48. vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/concurrent_test.cpython-310.pyc +0 -0
  49. vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/escape_test.cpython-310.pyc +0 -0
  50. vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/gen_test.cpython-310.pyc +0 -0
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/__init__.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .axislines import Axes
2
+ from .axislines import ( # noqa: F401
3
+ AxesZero, AxisArtistHelper, AxisArtistHelperRectlinear,
4
+ GridHelperBase, GridHelperRectlinear, Subplot, SubplotZero)
5
+ from .axis_artist import AxisArtist, GridlinesCollection # noqa: F401
6
+ from .grid_helper_curvelinear import GridHelperCurveLinear # noqa: F401
7
+ from .floating_axes import FloatingAxes, FloatingSubplot # noqa: F401
8
+ from mpl_toolkits.axes_grid1.parasite_axes import (
9
+ host_axes_class_factory, parasite_axes_class_factory)
10
+
11
+
12
+ ParasiteAxes = parasite_axes_class_factory(Axes)
13
+ HostAxes = host_axes_class_factory(Axes)
14
+ SubplotHost = HostAxes
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/angle_helper.py ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import math
3
+
4
+ from mpl_toolkits.axisartist.grid_finder import ExtremeFinderSimple
5
+
6
+
7
+ def select_step_degree(dv):
8
+
9
+ degree_limits_ = [1.5, 3, 7, 13, 20, 40, 70, 120, 270, 520]
10
+ degree_steps_ = [1, 2, 5, 10, 15, 30, 45, 90, 180, 360]
11
+ degree_factors = [1.] * len(degree_steps_)
12
+
13
+ minsec_limits_ = [1.5, 2.5, 3.5, 8, 11, 18, 25, 45]
14
+ minsec_steps_ = [1, 2, 3, 5, 10, 15, 20, 30]
15
+
16
+ minute_limits_ = np.array(minsec_limits_) / 60
17
+ minute_factors = [60.] * len(minute_limits_)
18
+
19
+ second_limits_ = np.array(minsec_limits_) / 3600
20
+ second_factors = [3600.] * len(second_limits_)
21
+
22
+ degree_limits = [*second_limits_, *minute_limits_, *degree_limits_]
23
+ degree_steps = [*minsec_steps_, *minsec_steps_, *degree_steps_]
24
+ degree_factors = [*second_factors, *minute_factors, *degree_factors]
25
+
26
+ n = np.searchsorted(degree_limits, dv)
27
+ step = degree_steps[n]
28
+ factor = degree_factors[n]
29
+
30
+ return step, factor
31
+
32
+
33
+ def select_step_hour(dv):
34
+
35
+ hour_limits_ = [1.5, 2.5, 3.5, 5, 7, 10, 15, 21, 36]
36
+ hour_steps_ = [1, 2, 3, 4, 6, 8, 12, 18, 24]
37
+ hour_factors = [1.] * len(hour_steps_)
38
+
39
+ minsec_limits_ = [1.5, 2.5, 3.5, 4.5, 5.5, 8, 11, 14, 18, 25, 45]
40
+ minsec_steps_ = [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30]
41
+
42
+ minute_limits_ = np.array(minsec_limits_) / 60
43
+ minute_factors = [60.] * len(minute_limits_)
44
+
45
+ second_limits_ = np.array(minsec_limits_) / 3600
46
+ second_factors = [3600.] * len(second_limits_)
47
+
48
+ hour_limits = [*second_limits_, *minute_limits_, *hour_limits_]
49
+ hour_steps = [*minsec_steps_, *minsec_steps_, *hour_steps_]
50
+ hour_factors = [*second_factors, *minute_factors, *hour_factors]
51
+
52
+ n = np.searchsorted(hour_limits, dv)
53
+ step = hour_steps[n]
54
+ factor = hour_factors[n]
55
+
56
+ return step, factor
57
+
58
+
59
+ def select_step_sub(dv):
60
+
61
+ # subarcsec or degree
62
+ tmp = 10.**(int(math.log10(dv))-1.)
63
+
64
+ factor = 1./tmp
65
+
66
+ if 1.5*tmp >= dv:
67
+ step = 1
68
+ elif 3.*tmp >= dv:
69
+ step = 2
70
+ elif 7.*tmp >= dv:
71
+ step = 5
72
+ else:
73
+ step = 1
74
+ factor = 0.1*factor
75
+
76
+ return step, factor
77
+
78
+
79
+ def select_step(v1, v2, nv, hour=False, include_last=True,
80
+ threshold_factor=3600.):
81
+
82
+ if v1 > v2:
83
+ v1, v2 = v2, v1
84
+
85
+ dv = (v2 - v1) / nv
86
+
87
+ if hour:
88
+ _select_step = select_step_hour
89
+ cycle = 24.
90
+ else:
91
+ _select_step = select_step_degree
92
+ cycle = 360.
93
+
94
+ # for degree
95
+ if dv > 1 / threshold_factor:
96
+ step, factor = _select_step(dv)
97
+ else:
98
+ step, factor = select_step_sub(dv*threshold_factor)
99
+
100
+ factor = factor * threshold_factor
101
+
102
+ levs = np.arange(np.floor(v1 * factor / step),
103
+ np.ceil(v2 * factor / step) + 0.5,
104
+ dtype=int) * step
105
+
106
+ # n : number of valid levels. If there is a cycle, e.g., [0, 90, 180,
107
+ # 270, 360], the grid line needs to be extended from 0 to 360, so
108
+ # we need to return the whole array. However, the last level (360)
109
+ # needs to be ignored often. In this case, so we return n=4.
110
+
111
+ n = len(levs)
112
+
113
+ # we need to check the range of values
114
+ # for example, -90 to 90, 0 to 360,
115
+
116
+ if factor == 1. and levs[-1] >= levs[0] + cycle: # check for cycle
117
+ nv = int(cycle / step)
118
+ if include_last:
119
+ levs = levs[0] + np.arange(0, nv+1, 1) * step
120
+ else:
121
+ levs = levs[0] + np.arange(0, nv, 1) * step
122
+
123
+ n = len(levs)
124
+
125
+ return np.array(levs), n, factor
126
+
127
+
128
+ def select_step24(v1, v2, nv, include_last=True, threshold_factor=3600):
129
+ v1, v2 = v1 / 15, v2 / 15
130
+ levs, n, factor = select_step(v1, v2, nv, hour=True,
131
+ include_last=include_last,
132
+ threshold_factor=threshold_factor)
133
+ return levs * 15, n, factor
134
+
135
+
136
+ def select_step360(v1, v2, nv, include_last=True, threshold_factor=3600):
137
+ return select_step(v1, v2, nv, hour=False,
138
+ include_last=include_last,
139
+ threshold_factor=threshold_factor)
140
+
141
+
142
+ class LocatorBase:
143
+ def __init__(self, nbins, include_last=True):
144
+ self.nbins = nbins
145
+ self._include_last = include_last
146
+
147
+ def set_params(self, nbins=None):
148
+ if nbins is not None:
149
+ self.nbins = int(nbins)
150
+
151
+
152
+ class LocatorHMS(LocatorBase):
153
+ def __call__(self, v1, v2):
154
+ return select_step24(v1, v2, self.nbins, self._include_last)
155
+
156
+
157
+ class LocatorHM(LocatorBase):
158
+ def __call__(self, v1, v2):
159
+ return select_step24(v1, v2, self.nbins, self._include_last,
160
+ threshold_factor=60)
161
+
162
+
163
+ class LocatorH(LocatorBase):
164
+ def __call__(self, v1, v2):
165
+ return select_step24(v1, v2, self.nbins, self._include_last,
166
+ threshold_factor=1)
167
+
168
+
169
+ class LocatorDMS(LocatorBase):
170
+ def __call__(self, v1, v2):
171
+ return select_step360(v1, v2, self.nbins, self._include_last)
172
+
173
+
174
+ class LocatorDM(LocatorBase):
175
+ def __call__(self, v1, v2):
176
+ return select_step360(v1, v2, self.nbins, self._include_last,
177
+ threshold_factor=60)
178
+
179
+
180
+ class LocatorD(LocatorBase):
181
+ def __call__(self, v1, v2):
182
+ return select_step360(v1, v2, self.nbins, self._include_last,
183
+ threshold_factor=1)
184
+
185
+
186
+ class FormatterDMS:
187
+ deg_mark = r"^{\circ}"
188
+ min_mark = r"^{\prime}"
189
+ sec_mark = r"^{\prime\prime}"
190
+
191
+ fmt_d = "$%d" + deg_mark + "$"
192
+ fmt_ds = r"$%d.%s" + deg_mark + "$"
193
+
194
+ # %s for sign
195
+ fmt_d_m = r"$%s%d" + deg_mark + r"\,%02d" + min_mark + "$"
196
+ fmt_d_ms = r"$%s%d" + deg_mark + r"\,%02d.%s" + min_mark + "$"
197
+
198
+ fmt_d_m_partial = "$%s%d" + deg_mark + r"\,%02d" + min_mark + r"\,"
199
+ fmt_s_partial = "%02d" + sec_mark + "$"
200
+ fmt_ss_partial = "%02d.%s" + sec_mark + "$"
201
+
202
+ def _get_number_fraction(self, factor):
203
+ ## check for fractional numbers
204
+ number_fraction = None
205
+ # check for 60
206
+
207
+ for threshold in [1, 60, 3600]:
208
+ if factor <= threshold:
209
+ break
210
+
211
+ d = factor // threshold
212
+ int_log_d = int(np.floor(np.log10(d)))
213
+ if 10**int_log_d == d and d != 1:
214
+ number_fraction = int_log_d
215
+ factor = factor // 10**int_log_d
216
+ return factor, number_fraction
217
+
218
+ return factor, number_fraction
219
+
220
+ def __call__(self, direction, factor, values):
221
+ if len(values) == 0:
222
+ return []
223
+
224
+ ss = np.sign(values)
225
+ signs = ["-" if v < 0 else "" for v in values]
226
+
227
+ factor, number_fraction = self._get_number_fraction(factor)
228
+
229
+ values = np.abs(values)
230
+
231
+ if number_fraction is not None:
232
+ values, frac_part = divmod(values, 10 ** number_fraction)
233
+ frac_fmt = "%%0%dd" % (number_fraction,)
234
+ frac_str = [frac_fmt % (f1,) for f1 in frac_part]
235
+
236
+ if factor == 1:
237
+ if number_fraction is None:
238
+ return [self.fmt_d % (s * int(v),) for s, v in zip(ss, values)]
239
+ else:
240
+ return [self.fmt_ds % (s * int(v), f1)
241
+ for s, v, f1 in zip(ss, values, frac_str)]
242
+ elif factor == 60:
243
+ deg_part, min_part = divmod(values, 60)
244
+ if number_fraction is None:
245
+ return [self.fmt_d_m % (s1, d1, m1)
246
+ for s1, d1, m1 in zip(signs, deg_part, min_part)]
247
+ else:
248
+ return [self.fmt_d_ms % (s, d1, m1, f1)
249
+ for s, d1, m1, f1
250
+ in zip(signs, deg_part, min_part, frac_str)]
251
+
252
+ elif factor == 3600:
253
+ if ss[-1] == -1:
254
+ inverse_order = True
255
+ values = values[::-1]
256
+ signs = signs[::-1]
257
+ else:
258
+ inverse_order = False
259
+
260
+ l_hm_old = ""
261
+ r = []
262
+
263
+ deg_part, min_part_ = divmod(values, 3600)
264
+ min_part, sec_part = divmod(min_part_, 60)
265
+
266
+ if number_fraction is None:
267
+ sec_str = [self.fmt_s_partial % (s1,) for s1 in sec_part]
268
+ else:
269
+ sec_str = [self.fmt_ss_partial % (s1, f1)
270
+ for s1, f1 in zip(sec_part, frac_str)]
271
+
272
+ for s, d1, m1, s1 in zip(signs, deg_part, min_part, sec_str):
273
+ l_hm = self.fmt_d_m_partial % (s, d1, m1)
274
+ if l_hm != l_hm_old:
275
+ l_hm_old = l_hm
276
+ l = l_hm + s1
277
+ else:
278
+ l = "$" + s + s1
279
+ r.append(l)
280
+
281
+ if inverse_order:
282
+ return r[::-1]
283
+ else:
284
+ return r
285
+
286
+ else: # factor > 3600.
287
+ return [r"$%s^{\circ}$" % v for v in ss*values]
288
+
289
+
290
+ class FormatterHMS(FormatterDMS):
291
+ deg_mark = r"^\mathrm{h}"
292
+ min_mark = r"^\mathrm{m}"
293
+ sec_mark = r"^\mathrm{s}"
294
+
295
+ fmt_d = "$%d" + deg_mark + "$"
296
+ fmt_ds = r"$%d.%s" + deg_mark + "$"
297
+
298
+ # %s for sign
299
+ fmt_d_m = r"$%s%d" + deg_mark + r"\,%02d" + min_mark+"$"
300
+ fmt_d_ms = r"$%s%d" + deg_mark + r"\,%02d.%s" + min_mark+"$"
301
+
302
+ fmt_d_m_partial = "$%s%d" + deg_mark + r"\,%02d" + min_mark + r"\,"
303
+ fmt_s_partial = "%02d" + sec_mark + "$"
304
+ fmt_ss_partial = "%02d.%s" + sec_mark + "$"
305
+
306
+ def __call__(self, direction, factor, values): # hour
307
+ return super().__call__(direction, factor, np.asarray(values) / 15)
308
+
309
+
310
+ class ExtremeFinderCycle(ExtremeFinderSimple):
311
+ # docstring inherited
312
+
313
+ def __init__(self, nx, ny,
314
+ lon_cycle=360., lat_cycle=None,
315
+ lon_minmax=None, lat_minmax=(-90, 90)):
316
+ """
317
+ This subclass handles the case where one or both coordinates should be
318
+ taken modulo 360, or be restricted to not exceed a specific range.
319
+
320
+ Parameters
321
+ ----------
322
+ nx, ny : int
323
+ The number of samples in each direction.
324
+
325
+ lon_cycle, lat_cycle : 360 or None
326
+ If not None, values in the corresponding direction are taken modulo
327
+ *lon_cycle* or *lat_cycle*; in theory this can be any number but
328
+ the implementation actually assumes that it is 360 (if not None);
329
+ other values give nonsensical results.
330
+
331
+ This is done by "unwrapping" the transformed grid coordinates so
332
+ that jumps are less than a half-cycle; then normalizing the span to
333
+ no more than a full cycle.
334
+
335
+ For example, if values are in the union of the [0, 2] and
336
+ [358, 360] intervals (typically, angles measured modulo 360), the
337
+ values in the second interval are normalized to [-2, 0] instead so
338
+ that the values now cover [-2, 2]. If values are in a range of
339
+ [5, 1000], this gets normalized to [5, 365].
340
+
341
+ lon_minmax, lat_minmax : (float, float) or None
342
+ If not None, the computed bounding box is clipped to the given
343
+ range in the corresponding direction.
344
+ """
345
+ self.nx, self.ny = nx, ny
346
+ self.lon_cycle, self.lat_cycle = lon_cycle, lat_cycle
347
+ self.lon_minmax = lon_minmax
348
+ self.lat_minmax = lat_minmax
349
+
350
+ def __call__(self, transform_xy, x1, y1, x2, y2):
351
+ # docstring inherited
352
+ x, y = np.meshgrid(
353
+ np.linspace(x1, x2, self.nx), np.linspace(y1, y2, self.ny))
354
+ lon, lat = transform_xy(np.ravel(x), np.ravel(y))
355
+
356
+ # iron out jumps, but algorithm should be improved.
357
+ # This is just naive way of doing and my fail for some cases.
358
+ # Consider replacing this with numpy.unwrap
359
+ # We are ignoring invalid warnings. They are triggered when
360
+ # comparing arrays with NaNs using > We are already handling
361
+ # that correctly using np.nanmin and np.nanmax
362
+ with np.errstate(invalid='ignore'):
363
+ if self.lon_cycle is not None:
364
+ lon0 = np.nanmin(lon)
365
+ lon -= 360. * ((lon - lon0) > 180.)
366
+ if self.lat_cycle is not None:
367
+ lat0 = np.nanmin(lat)
368
+ lat -= 360. * ((lat - lat0) > 180.)
369
+
370
+ lon_min, lon_max = np.nanmin(lon), np.nanmax(lon)
371
+ lat_min, lat_max = np.nanmin(lat), np.nanmax(lat)
372
+
373
+ lon_min, lon_max, lat_min, lat_max = \
374
+ self._add_pad(lon_min, lon_max, lat_min, lat_max)
375
+
376
+ # check cycle
377
+ if self.lon_cycle:
378
+ lon_max = min(lon_max, lon_min + self.lon_cycle)
379
+ if self.lat_cycle:
380
+ lat_max = min(lat_max, lat_min + self.lat_cycle)
381
+
382
+ if self.lon_minmax is not None:
383
+ min0 = self.lon_minmax[0]
384
+ lon_min = max(min0, lon_min)
385
+ max0 = self.lon_minmax[1]
386
+ lon_max = min(max0, lon_max)
387
+
388
+ if self.lat_minmax is not None:
389
+ min0 = self.lat_minmax[0]
390
+ lat_min = max(min0, lat_min)
391
+ max0 = self.lat_minmax[1]
392
+ lat_max = min(max0, lat_max)
393
+
394
+ return lon_min, lon_max, lat_min, lat_max
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axes_divider.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ from mpl_toolkits.axes_grid1.axes_divider import ( # noqa
2
+ Divider, SubplotDivider, AxesDivider, make_axes_locatable)
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axis_artist.py ADDED
@@ -0,0 +1,1115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ The :mod:`.axis_artist` module implements custom artists to draw axis elements
3
+ (axis lines and labels, tick lines and labels, grid lines).
4
+
5
+ Axis lines and labels and tick lines and labels are managed by the `AxisArtist`
6
+ class; grid lines are managed by the `GridlinesCollection` class.
7
+
8
+ There is one `AxisArtist` per Axis; it can be accessed through
9
+ the ``axis`` dictionary of the parent Axes (which should be a
10
+ `mpl_toolkits.axislines.Axes`), e.g. ``ax.axis["bottom"]``.
11
+
12
+ Children of the AxisArtist are accessed as attributes: ``.line`` and ``.label``
13
+ for the axis line and label, ``.major_ticks``, ``.major_ticklabels``,
14
+ ``.minor_ticks``, ``.minor_ticklabels`` for the tick lines and labels (e.g.
15
+ ``ax.axis["bottom"].line``).
16
+
17
+ Children properties (colors, fonts, line widths, etc.) can be set using
18
+ setters, e.g. ::
19
+
20
+ # Make the major ticks of the bottom axis red.
21
+ ax.axis["bottom"].major_ticks.set_color("red")
22
+
23
+ However, things like the locations of ticks, and their ticklabels need to be
24
+ changed from the side of the grid_helper.
25
+
26
+ axis_direction
27
+ --------------
28
+
29
+ `AxisArtist`, `AxisLabel`, `TickLabels` have an *axis_direction* attribute,
30
+ which adjusts the location, angle, etc. The *axis_direction* must be one of
31
+ "left", "right", "bottom", "top", and follows the Matplotlib convention for
32
+ rectangular axis.
33
+
34
+ For example, for the *bottom* axis (the left and right is relative to the
35
+ direction of the increasing coordinate),
36
+
37
+ * ticklabels and axislabel are on the right
38
+ * ticklabels and axislabel have text angle of 0
39
+ * ticklabels are baseline, center-aligned
40
+ * axislabel is top, center-aligned
41
+
42
+ The text angles are actually relative to (90 + angle of the direction to the
43
+ ticklabel), which gives 0 for bottom axis.
44
+
45
+ =================== ====== ======== ====== ========
46
+ Property left bottom right top
47
+ =================== ====== ======== ====== ========
48
+ ticklabel location left right right left
49
+ axislabel location left right right left
50
+ ticklabel angle 90 0 -90 180
51
+ axislabel angle 180 0 0 180
52
+ ticklabel va center baseline center baseline
53
+ axislabel va center top center bottom
54
+ ticklabel ha right center right center
55
+ axislabel ha right center right center
56
+ =================== ====== ======== ====== ========
57
+
58
+ Ticks are by default direct opposite side of the ticklabels. To make ticks to
59
+ the same side of the ticklabels, ::
60
+
61
+ ax.axis["bottom"].major_ticks.set_tick_out(True)
62
+
63
+ The following attributes can be customized (use the ``set_xxx`` methods):
64
+
65
+ * `Ticks`: ticksize, tick_out
66
+ * `TickLabels`: pad
67
+ * `AxisLabel`: pad
68
+ """
69
+
70
+ # FIXME :
71
+ # angles are given in data coordinate - need to convert it to canvas coordinate
72
+
73
+
74
+ from operator import methodcaller
75
+
76
+ import numpy as np
77
+
78
+ import matplotlib as mpl
79
+ from matplotlib import _api, cbook
80
+ import matplotlib.artist as martist
81
+ import matplotlib.colors as mcolors
82
+ import matplotlib.text as mtext
83
+ from matplotlib.collections import LineCollection
84
+ from matplotlib.lines import Line2D
85
+ from matplotlib.patches import PathPatch
86
+ from matplotlib.path import Path
87
+ from matplotlib.transforms import (
88
+ Affine2D, Bbox, IdentityTransform, ScaledTranslation)
89
+
90
+ from .axisline_style import AxislineStyle
91
+
92
+
93
+ class AttributeCopier:
94
+ def get_ref_artist(self):
95
+ """
96
+ Return the underlying artist that actually defines some properties
97
+ (e.g., color) of this artist.
98
+ """
99
+ raise RuntimeError("get_ref_artist must overridden")
100
+
101
+ def get_attribute_from_ref_artist(self, attr_name):
102
+ getter = methodcaller("get_" + attr_name)
103
+ prop = getter(super())
104
+ return getter(self.get_ref_artist()) if prop == "auto" else prop
105
+
106
+
107
+ class Ticks(AttributeCopier, Line2D):
108
+ """
109
+ Ticks are derived from `.Line2D`, and note that ticks themselves
110
+ are markers. Thus, you should use set_mec, set_mew, etc.
111
+
112
+ To change the tick size (length), you need to use
113
+ `set_ticksize`. To change the direction of the ticks (ticks are
114
+ in opposite direction of ticklabels by default), use
115
+ ``set_tick_out(False)``
116
+ """
117
+
118
+ def __init__(self, ticksize, tick_out=False, *, axis=None, **kwargs):
119
+ self._ticksize = ticksize
120
+ self.locs_angles_labels = []
121
+
122
+ self.set_tick_out(tick_out)
123
+
124
+ self._axis = axis
125
+ if self._axis is not None:
126
+ if "color" not in kwargs:
127
+ kwargs["color"] = "auto"
128
+ if "mew" not in kwargs and "markeredgewidth" not in kwargs:
129
+ kwargs["markeredgewidth"] = "auto"
130
+
131
+ Line2D.__init__(self, [0.], [0.], **kwargs)
132
+ self.set_snap(True)
133
+
134
+ def get_ref_artist(self):
135
+ # docstring inherited
136
+ return self._axis.majorTicks[0].tick1line
137
+
138
+ def set_color(self, color):
139
+ # docstring inherited
140
+ # Unlike the base Line2D.set_color, this also supports "auto".
141
+ if not cbook._str_equal(color, "auto"):
142
+ mcolors._check_color_like(color=color)
143
+ self._color = color
144
+ self.stale = True
145
+
146
+ def get_color(self):
147
+ return self.get_attribute_from_ref_artist("color")
148
+
149
+ def get_markeredgecolor(self):
150
+ return self.get_attribute_from_ref_artist("markeredgecolor")
151
+
152
+ def get_markeredgewidth(self):
153
+ return self.get_attribute_from_ref_artist("markeredgewidth")
154
+
155
+ def set_tick_out(self, b):
156
+ """Set whether ticks are drawn inside or outside the axes."""
157
+ self._tick_out = b
158
+
159
+ def get_tick_out(self):
160
+ """Return whether ticks are drawn inside or outside the axes."""
161
+ return self._tick_out
162
+
163
+ def set_ticksize(self, ticksize):
164
+ """Set length of the ticks in points."""
165
+ self._ticksize = ticksize
166
+
167
+ def get_ticksize(self):
168
+ """Return length of the ticks in points."""
169
+ return self._ticksize
170
+
171
+ def set_locs_angles(self, locs_angles):
172
+ self.locs_angles = locs_angles
173
+
174
+ _tickvert_path = Path([[0., 0.], [1., 0.]])
175
+
176
+ def draw(self, renderer):
177
+ if not self.get_visible():
178
+ return
179
+
180
+ gc = renderer.new_gc()
181
+ gc.set_foreground(self.get_markeredgecolor())
182
+ gc.set_linewidth(self.get_markeredgewidth())
183
+ gc.set_alpha(self._alpha)
184
+
185
+ path_trans = self.get_transform()
186
+ marker_transform = (Affine2D()
187
+ .scale(renderer.points_to_pixels(self._ticksize)))
188
+ if self.get_tick_out():
189
+ marker_transform.rotate_deg(180)
190
+
191
+ for loc, angle in self.locs_angles:
192
+ locs = path_trans.transform_non_affine(np.array([loc]))
193
+ if self.axes and not self.axes.viewLim.contains(*locs[0]):
194
+ continue
195
+ renderer.draw_markers(
196
+ gc, self._tickvert_path,
197
+ marker_transform + Affine2D().rotate_deg(angle),
198
+ Path(locs), path_trans.get_affine())
199
+
200
+ gc.restore()
201
+
202
+
203
+ class LabelBase(mtext.Text):
204
+ """
205
+ A base class for `.AxisLabel` and `.TickLabels`. The position and
206
+ angle of the text are calculated by the offset_ref_angle,
207
+ text_ref_angle, and offset_radius attributes.
208
+ """
209
+
210
+ def __init__(self, *args, **kwargs):
211
+ self.locs_angles_labels = []
212
+ self._ref_angle = 0
213
+ self._offset_radius = 0.
214
+
215
+ super().__init__(*args, **kwargs)
216
+
217
+ self.set_rotation_mode("anchor")
218
+ self._text_follow_ref_angle = True
219
+
220
+ @property
221
+ def _text_ref_angle(self):
222
+ if self._text_follow_ref_angle:
223
+ return self._ref_angle + 90
224
+ else:
225
+ return 0
226
+
227
+ @property
228
+ def _offset_ref_angle(self):
229
+ return self._ref_angle
230
+
231
+ _get_opposite_direction = {"left": "right",
232
+ "right": "left",
233
+ "top": "bottom",
234
+ "bottom": "top"}.__getitem__
235
+
236
+ def draw(self, renderer):
237
+ if not self.get_visible():
238
+ return
239
+
240
+ # save original and adjust some properties
241
+ tr = self.get_transform()
242
+ angle_orig = self.get_rotation()
243
+ theta = np.deg2rad(self._offset_ref_angle)
244
+ dd = self._offset_radius
245
+ dx, dy = dd * np.cos(theta), dd * np.sin(theta)
246
+
247
+ self.set_transform(tr + Affine2D().translate(dx, dy))
248
+ self.set_rotation(self._text_ref_angle + angle_orig)
249
+ super().draw(renderer)
250
+ # restore original properties
251
+ self.set_transform(tr)
252
+ self.set_rotation(angle_orig)
253
+
254
+ def get_window_extent(self, renderer=None):
255
+ if renderer is None:
256
+ renderer = self.get_figure(root=True)._get_renderer()
257
+
258
+ # save original and adjust some properties
259
+ tr = self.get_transform()
260
+ angle_orig = self.get_rotation()
261
+ theta = np.deg2rad(self._offset_ref_angle)
262
+ dd = self._offset_radius
263
+ dx, dy = dd * np.cos(theta), dd * np.sin(theta)
264
+
265
+ self.set_transform(tr + Affine2D().translate(dx, dy))
266
+ self.set_rotation(self._text_ref_angle + angle_orig)
267
+ bbox = super().get_window_extent(renderer).frozen()
268
+ # restore original properties
269
+ self.set_transform(tr)
270
+ self.set_rotation(angle_orig)
271
+
272
+ return bbox
273
+
274
+
275
+ class AxisLabel(AttributeCopier, LabelBase):
276
+ """
277
+ Axis label. Derived from `.Text`. The position of the text is updated
278
+ in the fly, so changing text position has no effect. Otherwise, the
279
+ properties can be changed as a normal `.Text`.
280
+
281
+ To change the pad between tick labels and axis label, use `set_pad`.
282
+ """
283
+
284
+ def __init__(self, *args, axis_direction="bottom", axis=None, **kwargs):
285
+ self._axis = axis
286
+ self._pad = 5
287
+ self._external_pad = 0 # in pixels
288
+ LabelBase.__init__(self, *args, **kwargs)
289
+ self.set_axis_direction(axis_direction)
290
+
291
+ def set_pad(self, pad):
292
+ """
293
+ Set the internal pad in points.
294
+
295
+ The actual pad will be the sum of the internal pad and the
296
+ external pad (the latter is set automatically by the `.AxisArtist`).
297
+
298
+ Parameters
299
+ ----------
300
+ pad : float
301
+ The internal pad in points.
302
+ """
303
+ self._pad = pad
304
+
305
+ def get_pad(self):
306
+ """
307
+ Return the internal pad in points.
308
+
309
+ See `.set_pad` for more details.
310
+ """
311
+ return self._pad
312
+
313
+ def get_ref_artist(self):
314
+ # docstring inherited
315
+ return self._axis.label
316
+
317
+ def get_text(self):
318
+ # docstring inherited
319
+ t = super().get_text()
320
+ if t == "__from_axes__":
321
+ return self._axis.label.get_text()
322
+ return self._text
323
+
324
+ _default_alignments = dict(left=("bottom", "center"),
325
+ right=("top", "center"),
326
+ bottom=("top", "center"),
327
+ top=("bottom", "center"))
328
+
329
+ def set_default_alignment(self, d):
330
+ """
331
+ Set the default alignment. See `set_axis_direction` for details.
332
+
333
+ Parameters
334
+ ----------
335
+ d : {"left", "bottom", "right", "top"}
336
+ """
337
+ va, ha = _api.check_getitem(self._default_alignments, d=d)
338
+ self.set_va(va)
339
+ self.set_ha(ha)
340
+
341
+ _default_angles = dict(left=180,
342
+ right=0,
343
+ bottom=0,
344
+ top=180)
345
+
346
+ def set_default_angle(self, d):
347
+ """
348
+ Set the default angle. See `set_axis_direction` for details.
349
+
350
+ Parameters
351
+ ----------
352
+ d : {"left", "bottom", "right", "top"}
353
+ """
354
+ self.set_rotation(_api.check_getitem(self._default_angles, d=d))
355
+
356
+ def set_axis_direction(self, d):
357
+ """
358
+ Adjust the text angle and text alignment of axis label
359
+ according to the matplotlib convention.
360
+
361
+ ===================== ========== ========= ========== ==========
362
+ Property left bottom right top
363
+ ===================== ========== ========= ========== ==========
364
+ axislabel angle 180 0 0 180
365
+ axislabel va center top center bottom
366
+ axislabel ha right center right center
367
+ ===================== ========== ========= ========== ==========
368
+
369
+ Note that the text angles are actually relative to (90 + angle
370
+ of the direction to the ticklabel), which gives 0 for bottom
371
+ axis.
372
+
373
+ Parameters
374
+ ----------
375
+ d : {"left", "bottom", "right", "top"}
376
+ """
377
+ self.set_default_alignment(d)
378
+ self.set_default_angle(d)
379
+
380
+ def get_color(self):
381
+ return self.get_attribute_from_ref_artist("color")
382
+
383
+ def draw(self, renderer):
384
+ if not self.get_visible():
385
+ return
386
+
387
+ self._offset_radius = \
388
+ self._external_pad + renderer.points_to_pixels(self.get_pad())
389
+
390
+ super().draw(renderer)
391
+
392
+ def get_window_extent(self, renderer=None):
393
+ if renderer is None:
394
+ renderer = self.get_figure(root=True)._get_renderer()
395
+ if not self.get_visible():
396
+ return
397
+
398
+ r = self._external_pad + renderer.points_to_pixels(self.get_pad())
399
+ self._offset_radius = r
400
+
401
+ bb = super().get_window_extent(renderer)
402
+
403
+ return bb
404
+
405
+
406
+ class TickLabels(AxisLabel): # mtext.Text
407
+ """
408
+ Tick labels. While derived from `.Text`, this single artist draws all
409
+ ticklabels. As in `.AxisLabel`, the position of the text is updated
410
+ in the fly, so changing text position has no effect. Otherwise,
411
+ the properties can be changed as a normal `.Text`. Unlike the
412
+ ticklabels of the mainline Matplotlib, properties of a single
413
+ ticklabel alone cannot be modified.
414
+
415
+ To change the pad between ticks and ticklabels, use `~.AxisLabel.set_pad`.
416
+ """
417
+
418
+ def __init__(self, *, axis_direction="bottom", **kwargs):
419
+ super().__init__(**kwargs)
420
+ self.set_axis_direction(axis_direction)
421
+ self._axislabel_pad = 0
422
+
423
+ def get_ref_artist(self):
424
+ # docstring inherited
425
+ return self._axis.get_ticklabels()[0]
426
+
427
+ def set_axis_direction(self, label_direction):
428
+ """
429
+ Adjust the text angle and text alignment of ticklabels
430
+ according to the Matplotlib convention.
431
+
432
+ The *label_direction* must be one of [left, right, bottom, top].
433
+
434
+ ===================== ========== ========= ========== ==========
435
+ Property left bottom right top
436
+ ===================== ========== ========= ========== ==========
437
+ ticklabel angle 90 0 -90 180
438
+ ticklabel va center baseline center baseline
439
+ ticklabel ha right center right center
440
+ ===================== ========== ========= ========== ==========
441
+
442
+ Note that the text angles are actually relative to (90 + angle
443
+ of the direction to the ticklabel), which gives 0 for bottom
444
+ axis.
445
+
446
+ Parameters
447
+ ----------
448
+ label_direction : {"left", "bottom", "right", "top"}
449
+
450
+ """
451
+ self.set_default_alignment(label_direction)
452
+ self.set_default_angle(label_direction)
453
+ self._axis_direction = label_direction
454
+
455
+ def invert_axis_direction(self):
456
+ label_direction = self._get_opposite_direction(self._axis_direction)
457
+ self.set_axis_direction(label_direction)
458
+
459
+ def _get_ticklabels_offsets(self, renderer, label_direction):
460
+ """
461
+ Calculate the ticklabel offsets from the tick and their total heights.
462
+
463
+ The offset only takes account the offset due to the vertical alignment
464
+ of the ticklabels: if axis direction is bottom and va is 'top', it will
465
+ return 0; if va is 'baseline', it will return (height-descent).
466
+ """
467
+ whd_list = self.get_texts_widths_heights_descents(renderer)
468
+
469
+ if not whd_list:
470
+ return 0, 0
471
+
472
+ r = 0
473
+ va, ha = self.get_va(), self.get_ha()
474
+
475
+ if label_direction == "left":
476
+ pad = max(w for w, h, d in whd_list)
477
+ if ha == "left":
478
+ r = pad
479
+ elif ha == "center":
480
+ r = .5 * pad
481
+ elif label_direction == "right":
482
+ pad = max(w for w, h, d in whd_list)
483
+ if ha == "right":
484
+ r = pad
485
+ elif ha == "center":
486
+ r = .5 * pad
487
+ elif label_direction == "bottom":
488
+ pad = max(h for w, h, d in whd_list)
489
+ if va == "bottom":
490
+ r = pad
491
+ elif va == "center":
492
+ r = .5 * pad
493
+ elif va == "baseline":
494
+ max_ascent = max(h - d for w, h, d in whd_list)
495
+ max_descent = max(d for w, h, d in whd_list)
496
+ r = max_ascent
497
+ pad = max_ascent + max_descent
498
+ elif label_direction == "top":
499
+ pad = max(h for w, h, d in whd_list)
500
+ if va == "top":
501
+ r = pad
502
+ elif va == "center":
503
+ r = .5 * pad
504
+ elif va == "baseline":
505
+ max_ascent = max(h - d for w, h, d in whd_list)
506
+ max_descent = max(d for w, h, d in whd_list)
507
+ r = max_descent
508
+ pad = max_ascent + max_descent
509
+
510
+ # r : offset
511
+ # pad : total height of the ticklabels. This will be used to
512
+ # calculate the pad for the axislabel.
513
+ return r, pad
514
+
515
+ _default_alignments = dict(left=("center", "right"),
516
+ right=("center", "left"),
517
+ bottom=("baseline", "center"),
518
+ top=("baseline", "center"))
519
+
520
+ _default_angles = dict(left=90,
521
+ right=-90,
522
+ bottom=0,
523
+ top=180)
524
+
525
+ def draw(self, renderer):
526
+ if not self.get_visible():
527
+ self._axislabel_pad = self._external_pad
528
+ return
529
+
530
+ r, total_width = self._get_ticklabels_offsets(renderer,
531
+ self._axis_direction)
532
+
533
+ pad = self._external_pad + renderer.points_to_pixels(self.get_pad())
534
+ self._offset_radius = r + pad
535
+
536
+ for (x, y), a, l in self._locs_angles_labels:
537
+ if not l.strip():
538
+ continue
539
+ self._ref_angle = a
540
+ self.set_x(x)
541
+ self.set_y(y)
542
+ self.set_text(l)
543
+ LabelBase.draw(self, renderer)
544
+
545
+ # the value saved will be used to draw axislabel.
546
+ self._axislabel_pad = total_width + pad
547
+
548
+ def set_locs_angles_labels(self, locs_angles_labels):
549
+ self._locs_angles_labels = locs_angles_labels
550
+
551
+ def get_window_extents(self, renderer=None):
552
+ if renderer is None:
553
+ renderer = self.get_figure(root=True)._get_renderer()
554
+
555
+ if not self.get_visible():
556
+ self._axislabel_pad = self._external_pad
557
+ return []
558
+
559
+ bboxes = []
560
+
561
+ r, total_width = self._get_ticklabels_offsets(renderer,
562
+ self._axis_direction)
563
+
564
+ pad = self._external_pad + renderer.points_to_pixels(self.get_pad())
565
+ self._offset_radius = r + pad
566
+
567
+ for (x, y), a, l in self._locs_angles_labels:
568
+ self._ref_angle = a
569
+ self.set_x(x)
570
+ self.set_y(y)
571
+ self.set_text(l)
572
+ bb = LabelBase.get_window_extent(self, renderer)
573
+ bboxes.append(bb)
574
+
575
+ # the value saved will be used to draw axislabel.
576
+ self._axislabel_pad = total_width + pad
577
+
578
+ return bboxes
579
+
580
+ def get_texts_widths_heights_descents(self, renderer):
581
+ """
582
+ Return a list of ``(width, height, descent)`` tuples for ticklabels.
583
+
584
+ Empty labels are left out.
585
+ """
586
+ whd_list = []
587
+ for _loc, _angle, label in self._locs_angles_labels:
588
+ if not label.strip():
589
+ continue
590
+ clean_line, ismath = self._preprocess_math(label)
591
+ whd = renderer.get_text_width_height_descent(
592
+ clean_line, self._fontproperties, ismath=ismath)
593
+ whd_list.append(whd)
594
+ return whd_list
595
+
596
+
597
+ class GridlinesCollection(LineCollection):
598
+ def __init__(self, *args, which="major", axis="both", **kwargs):
599
+ """
600
+ Collection of grid lines.
601
+
602
+ Parameters
603
+ ----------
604
+ which : {"major", "minor"}
605
+ Which grid to consider.
606
+ axis : {"both", "x", "y"}
607
+ Which axis to consider.
608
+ *args, **kwargs
609
+ Passed to `.LineCollection`.
610
+ """
611
+ self._which = which
612
+ self._axis = axis
613
+ super().__init__(*args, **kwargs)
614
+ self.set_grid_helper(None)
615
+
616
+ def set_which(self, which):
617
+ """
618
+ Select major or minor grid lines.
619
+
620
+ Parameters
621
+ ----------
622
+ which : {"major", "minor"}
623
+ """
624
+ self._which = which
625
+
626
+ def set_axis(self, axis):
627
+ """
628
+ Select axis.
629
+
630
+ Parameters
631
+ ----------
632
+ axis : {"both", "x", "y"}
633
+ """
634
+ self._axis = axis
635
+
636
+ def set_grid_helper(self, grid_helper):
637
+ """
638
+ Set grid helper.
639
+
640
+ Parameters
641
+ ----------
642
+ grid_helper : `.GridHelperBase` subclass
643
+ """
644
+ self._grid_helper = grid_helper
645
+
646
+ def draw(self, renderer):
647
+ if self._grid_helper is not None:
648
+ self._grid_helper.update_lim(self.axes)
649
+ gl = self._grid_helper.get_gridlines(self._which, self._axis)
650
+ self.set_segments([np.transpose(l) for l in gl])
651
+ super().draw(renderer)
652
+
653
+
654
+ class AxisArtist(martist.Artist):
655
+ """
656
+ An artist which draws axis (a line along which the n-th axes coord
657
+ is constant) line, ticks, tick labels, and axis label.
658
+ """
659
+
660
+ zorder = 2.5
661
+
662
+ @property
663
+ def LABELPAD(self):
664
+ return self.label.get_pad()
665
+
666
+ @LABELPAD.setter
667
+ def LABELPAD(self, v):
668
+ self.label.set_pad(v)
669
+
670
+ def __init__(self, axes,
671
+ helper,
672
+ offset=None,
673
+ axis_direction="bottom",
674
+ **kwargs):
675
+ """
676
+ Parameters
677
+ ----------
678
+ axes : `mpl_toolkits.axisartist.axislines.Axes`
679
+ helper : `~mpl_toolkits.axisartist.axislines.AxisArtistHelper`
680
+ """
681
+ # axes is also used to follow the axis attribute (tick color, etc).
682
+
683
+ super().__init__(**kwargs)
684
+
685
+ self.axes = axes
686
+
687
+ self._axis_artist_helper = helper
688
+
689
+ if offset is None:
690
+ offset = (0, 0)
691
+ self.offset_transform = ScaledTranslation(
692
+ *offset,
693
+ Affine2D().scale(1 / 72) # points to inches.
694
+ + self.axes.get_figure(root=False).dpi_scale_trans)
695
+
696
+ if axis_direction in ["left", "right"]:
697
+ self.axis = axes.yaxis
698
+ else:
699
+ self.axis = axes.xaxis
700
+
701
+ self._axisline_style = None
702
+ self._axis_direction = axis_direction
703
+
704
+ self._init_line()
705
+ self._init_ticks(**kwargs)
706
+ self._init_offsetText(axis_direction)
707
+ self._init_label()
708
+
709
+ # axis direction
710
+ self._ticklabel_add_angle = 0.
711
+ self._axislabel_add_angle = 0.
712
+ self.set_axis_direction(axis_direction)
713
+
714
+ # axis direction
715
+
716
+ def set_axis_direction(self, axis_direction):
717
+ """
718
+ Adjust the direction, text angle, and text alignment of tick labels
719
+ and axis labels following the Matplotlib convention for the rectangle
720
+ axes.
721
+
722
+ The *axis_direction* must be one of [left, right, bottom, top].
723
+
724
+ ===================== ========== ========= ========== ==========
725
+ Property left bottom right top
726
+ ===================== ========== ========= ========== ==========
727
+ ticklabel direction "-" "+" "+" "-"
728
+ axislabel direction "-" "+" "+" "-"
729
+ ticklabel angle 90 0 -90 180
730
+ ticklabel va center baseline center baseline
731
+ ticklabel ha right center right center
732
+ axislabel angle 180 0 0 180
733
+ axislabel va center top center bottom
734
+ axislabel ha right center right center
735
+ ===================== ========== ========= ========== ==========
736
+
737
+ Note that the direction "+" and "-" are relative to the direction of
738
+ the increasing coordinate. Also, the text angles are actually
739
+ relative to (90 + angle of the direction to the ticklabel),
740
+ which gives 0 for bottom axis.
741
+
742
+ Parameters
743
+ ----------
744
+ axis_direction : {"left", "bottom", "right", "top"}
745
+ """
746
+ self.major_ticklabels.set_axis_direction(axis_direction)
747
+ self.label.set_axis_direction(axis_direction)
748
+ self._axis_direction = axis_direction
749
+ if axis_direction in ["left", "top"]:
750
+ self.set_ticklabel_direction("-")
751
+ self.set_axislabel_direction("-")
752
+ else:
753
+ self.set_ticklabel_direction("+")
754
+ self.set_axislabel_direction("+")
755
+
756
+ def set_ticklabel_direction(self, tick_direction):
757
+ r"""
758
+ Adjust the direction of the tick labels.
759
+
760
+ Note that the *tick_direction*\s '+' and '-' are relative to the
761
+ direction of the increasing coordinate.
762
+
763
+ Parameters
764
+ ----------
765
+ tick_direction : {"+", "-"}
766
+ """
767
+ self._ticklabel_add_angle = _api.check_getitem(
768
+ {"+": 0, "-": 180}, tick_direction=tick_direction)
769
+
770
+ def invert_ticklabel_direction(self):
771
+ self._ticklabel_add_angle = (self._ticklabel_add_angle + 180) % 360
772
+ self.major_ticklabels.invert_axis_direction()
773
+ self.minor_ticklabels.invert_axis_direction()
774
+
775
+ def set_axislabel_direction(self, label_direction):
776
+ r"""
777
+ Adjust the direction of the axis label.
778
+
779
+ Note that the *label_direction*\s '+' and '-' are relative to the
780
+ direction of the increasing coordinate.
781
+
782
+ Parameters
783
+ ----------
784
+ label_direction : {"+", "-"}
785
+ """
786
+ self._axislabel_add_angle = _api.check_getitem(
787
+ {"+": 0, "-": 180}, label_direction=label_direction)
788
+
789
+ def get_transform(self):
790
+ return self.axes.transAxes + self.offset_transform
791
+
792
+ def get_helper(self):
793
+ """
794
+ Return axis artist helper instance.
795
+ """
796
+ return self._axis_artist_helper
797
+
798
+ def set_axisline_style(self, axisline_style=None, **kwargs):
799
+ """
800
+ Set the axisline style.
801
+
802
+ The new style is completely defined by the passed attributes. Existing
803
+ style attributes are forgotten.
804
+
805
+ Parameters
806
+ ----------
807
+ axisline_style : str or None
808
+ The line style, e.g. '->', optionally followed by a comma-separated
809
+ list of attributes. Alternatively, the attributes can be provided
810
+ as keywords.
811
+
812
+ If *None* this returns a string containing the available styles.
813
+
814
+ Examples
815
+ --------
816
+ The following two commands are equal:
817
+
818
+ >>> set_axisline_style("->,size=1.5")
819
+ >>> set_axisline_style("->", size=1.5)
820
+ """
821
+ if axisline_style is None:
822
+ return AxislineStyle.pprint_styles()
823
+
824
+ if isinstance(axisline_style, AxislineStyle._Base):
825
+ self._axisline_style = axisline_style
826
+ else:
827
+ self._axisline_style = AxislineStyle(axisline_style, **kwargs)
828
+
829
+ self._init_line()
830
+
831
+ def get_axisline_style(self):
832
+ """Return the current axisline style."""
833
+ return self._axisline_style
834
+
835
+ def _init_line(self):
836
+ """
837
+ Initialize the *line* artist that is responsible to draw the axis line.
838
+ """
839
+ tran = (self._axis_artist_helper.get_line_transform(self.axes)
840
+ + self.offset_transform)
841
+
842
+ axisline_style = self.get_axisline_style()
843
+ if axisline_style is None:
844
+ self.line = PathPatch(
845
+ self._axis_artist_helper.get_line(self.axes),
846
+ color=mpl.rcParams['axes.edgecolor'],
847
+ fill=False,
848
+ linewidth=mpl.rcParams['axes.linewidth'],
849
+ capstyle=mpl.rcParams['lines.solid_capstyle'],
850
+ joinstyle=mpl.rcParams['lines.solid_joinstyle'],
851
+ transform=tran)
852
+ else:
853
+ self.line = axisline_style(self, transform=tran)
854
+
855
+ def _draw_line(self, renderer):
856
+ self.line.set_path(self._axis_artist_helper.get_line(self.axes))
857
+ if self.get_axisline_style() is not None:
858
+ self.line.set_line_mutation_scale(self.major_ticklabels.get_size())
859
+ self.line.draw(renderer)
860
+
861
+ def _init_ticks(self, **kwargs):
862
+ axis_name = self.axis.axis_name
863
+
864
+ trans = (self._axis_artist_helper.get_tick_transform(self.axes)
865
+ + self.offset_transform)
866
+
867
+ self.major_ticks = Ticks(
868
+ kwargs.get(
869
+ "major_tick_size",
870
+ mpl.rcParams[f"{axis_name}tick.major.size"]),
871
+ axis=self.axis, transform=trans)
872
+ self.minor_ticks = Ticks(
873
+ kwargs.get(
874
+ "minor_tick_size",
875
+ mpl.rcParams[f"{axis_name}tick.minor.size"]),
876
+ axis=self.axis, transform=trans)
877
+
878
+ size = mpl.rcParams[f"{axis_name}tick.labelsize"]
879
+ self.major_ticklabels = TickLabels(
880
+ axis=self.axis,
881
+ axis_direction=self._axis_direction,
882
+ figure=self.axes.get_figure(root=False),
883
+ transform=trans,
884
+ fontsize=size,
885
+ pad=kwargs.get(
886
+ "major_tick_pad", mpl.rcParams[f"{axis_name}tick.major.pad"]),
887
+ )
888
+ self.minor_ticklabels = TickLabels(
889
+ axis=self.axis,
890
+ axis_direction=self._axis_direction,
891
+ figure=self.axes.get_figure(root=False),
892
+ transform=trans,
893
+ fontsize=size,
894
+ pad=kwargs.get(
895
+ "minor_tick_pad", mpl.rcParams[f"{axis_name}tick.minor.pad"]),
896
+ )
897
+
898
+ def _get_tick_info(self, tick_iter):
899
+ """
900
+ Return a pair of:
901
+
902
+ - list of locs and angles for ticks
903
+ - list of locs, angles and labels for ticklabels.
904
+ """
905
+ ticks_loc_angle = []
906
+ ticklabels_loc_angle_label = []
907
+
908
+ ticklabel_add_angle = self._ticklabel_add_angle
909
+
910
+ for loc, angle_normal, angle_tangent, label in tick_iter:
911
+ angle_label = angle_tangent - 90 + ticklabel_add_angle
912
+ angle_tick = (angle_normal
913
+ if 90 <= (angle_label - angle_normal) % 360 <= 270
914
+ else angle_normal + 180)
915
+ ticks_loc_angle.append([loc, angle_tick])
916
+ ticklabels_loc_angle_label.append([loc, angle_label, label])
917
+
918
+ return ticks_loc_angle, ticklabels_loc_angle_label
919
+
920
+ def _update_ticks(self, renderer=None):
921
+ # set extra pad for major and minor ticklabels: use ticksize of
922
+ # majorticks even for minor ticks. not clear what is best.
923
+
924
+ if renderer is None:
925
+ renderer = self.get_figure(root=True)._get_renderer()
926
+
927
+ dpi_cor = renderer.points_to_pixels(1.)
928
+ if self.major_ticks.get_visible() and self.major_ticks.get_tick_out():
929
+ ticklabel_pad = self.major_ticks._ticksize * dpi_cor
930
+ self.major_ticklabels._external_pad = ticklabel_pad
931
+ self.minor_ticklabels._external_pad = ticklabel_pad
932
+ else:
933
+ self.major_ticklabels._external_pad = 0
934
+ self.minor_ticklabels._external_pad = 0
935
+
936
+ majortick_iter, minortick_iter = \
937
+ self._axis_artist_helper.get_tick_iterators(self.axes)
938
+
939
+ tick_loc_angle, ticklabel_loc_angle_label = \
940
+ self._get_tick_info(majortick_iter)
941
+ self.major_ticks.set_locs_angles(tick_loc_angle)
942
+ self.major_ticklabels.set_locs_angles_labels(ticklabel_loc_angle_label)
943
+
944
+ tick_loc_angle, ticklabel_loc_angle_label = \
945
+ self._get_tick_info(minortick_iter)
946
+ self.minor_ticks.set_locs_angles(tick_loc_angle)
947
+ self.minor_ticklabels.set_locs_angles_labels(ticklabel_loc_angle_label)
948
+
949
+ def _draw_ticks(self, renderer):
950
+ self._update_ticks(renderer)
951
+ self.major_ticks.draw(renderer)
952
+ self.major_ticklabels.draw(renderer)
953
+ self.minor_ticks.draw(renderer)
954
+ self.minor_ticklabels.draw(renderer)
955
+ if (self.major_ticklabels.get_visible()
956
+ or self.minor_ticklabels.get_visible()):
957
+ self._draw_offsetText(renderer)
958
+
959
+ _offsetText_pos = dict(left=(0, 1, "bottom", "right"),
960
+ right=(1, 1, "bottom", "left"),
961
+ bottom=(1, 0, "top", "right"),
962
+ top=(1, 1, "bottom", "right"))
963
+
964
+ def _init_offsetText(self, direction):
965
+ x, y, va, ha = self._offsetText_pos[direction]
966
+ self.offsetText = mtext.Annotation(
967
+ "",
968
+ xy=(x, y), xycoords="axes fraction",
969
+ xytext=(0, 0), textcoords="offset points",
970
+ color=mpl.rcParams['xtick.color'],
971
+ horizontalalignment=ha, verticalalignment=va,
972
+ )
973
+ self.offsetText.set_transform(IdentityTransform())
974
+ self.axes._set_artist_props(self.offsetText)
975
+
976
+ def _update_offsetText(self):
977
+ self.offsetText.set_text(self.axis.major.formatter.get_offset())
978
+ self.offsetText.set_size(self.major_ticklabels.get_size())
979
+ offset = (self.major_ticklabels.get_pad()
980
+ + self.major_ticklabels.get_size()
981
+ + 2)
982
+ self.offsetText.xyann = (0, offset)
983
+
984
+ def _draw_offsetText(self, renderer):
985
+ self._update_offsetText()
986
+ self.offsetText.draw(renderer)
987
+
988
+ def _init_label(self, **kwargs):
989
+ tr = (self._axis_artist_helper.get_axislabel_transform(self.axes)
990
+ + self.offset_transform)
991
+ self.label = AxisLabel(
992
+ 0, 0, "__from_axes__",
993
+ color="auto",
994
+ fontsize=kwargs.get("labelsize", mpl.rcParams['axes.labelsize']),
995
+ fontweight=mpl.rcParams['axes.labelweight'],
996
+ axis=self.axis,
997
+ transform=tr,
998
+ axis_direction=self._axis_direction,
999
+ )
1000
+ self.label.set_figure(self.axes.get_figure(root=False))
1001
+ labelpad = kwargs.get("labelpad", 5)
1002
+ self.label.set_pad(labelpad)
1003
+
1004
+ def _update_label(self, renderer):
1005
+ if not self.label.get_visible():
1006
+ return
1007
+
1008
+ if self._ticklabel_add_angle != self._axislabel_add_angle:
1009
+ if ((self.major_ticks.get_visible()
1010
+ and not self.major_ticks.get_tick_out())
1011
+ or (self.minor_ticks.get_visible()
1012
+ and not self.major_ticks.get_tick_out())):
1013
+ axislabel_pad = self.major_ticks._ticksize
1014
+ else:
1015
+ axislabel_pad = 0
1016
+ else:
1017
+ axislabel_pad = max(self.major_ticklabels._axislabel_pad,
1018
+ self.minor_ticklabels._axislabel_pad)
1019
+
1020
+ self.label._external_pad = axislabel_pad
1021
+
1022
+ xy, angle_tangent = \
1023
+ self._axis_artist_helper.get_axislabel_pos_angle(self.axes)
1024
+ if xy is None:
1025
+ return
1026
+
1027
+ angle_label = angle_tangent - 90
1028
+
1029
+ x, y = xy
1030
+ self.label._ref_angle = angle_label + self._axislabel_add_angle
1031
+ self.label.set(x=x, y=y)
1032
+
1033
+ def _draw_label(self, renderer):
1034
+ self._update_label(renderer)
1035
+ self.label.draw(renderer)
1036
+
1037
+ def set_label(self, s):
1038
+ # docstring inherited
1039
+ self.label.set_text(s)
1040
+
1041
+ def get_tightbbox(self, renderer=None):
1042
+ if not self.get_visible():
1043
+ return
1044
+ self._axis_artist_helper.update_lim(self.axes)
1045
+ self._update_ticks(renderer)
1046
+ self._update_label(renderer)
1047
+
1048
+ self.line.set_path(self._axis_artist_helper.get_line(self.axes))
1049
+ if self.get_axisline_style() is not None:
1050
+ self.line.set_line_mutation_scale(self.major_ticklabels.get_size())
1051
+
1052
+ bb = [
1053
+ *self.major_ticklabels.get_window_extents(renderer),
1054
+ *self.minor_ticklabels.get_window_extents(renderer),
1055
+ self.label.get_window_extent(renderer),
1056
+ self.offsetText.get_window_extent(renderer),
1057
+ self.line.get_window_extent(renderer),
1058
+ ]
1059
+ bb = [b for b in bb if b and (b.width != 0 or b.height != 0)]
1060
+ if bb:
1061
+ _bbox = Bbox.union(bb)
1062
+ return _bbox
1063
+ else:
1064
+ return None
1065
+
1066
+ @martist.allow_rasterization
1067
+ def draw(self, renderer):
1068
+ # docstring inherited
1069
+ if not self.get_visible():
1070
+ return
1071
+ renderer.open_group(__name__, gid=self.get_gid())
1072
+ self._axis_artist_helper.update_lim(self.axes)
1073
+ self._draw_ticks(renderer)
1074
+ self._draw_line(renderer)
1075
+ self._draw_label(renderer)
1076
+ renderer.close_group(__name__)
1077
+
1078
+ def toggle(self, all=None, ticks=None, ticklabels=None, label=None):
1079
+ """
1080
+ Toggle visibility of ticks, ticklabels, and (axis) label.
1081
+ To turn all off, ::
1082
+
1083
+ axis.toggle(all=False)
1084
+
1085
+ To turn all off but ticks on ::
1086
+
1087
+ axis.toggle(all=False, ticks=True)
1088
+
1089
+ To turn all on but (axis) label off ::
1090
+
1091
+ axis.toggle(all=True, label=False)
1092
+
1093
+ """
1094
+ if all:
1095
+ _ticks, _ticklabels, _label = True, True, True
1096
+ elif all is not None:
1097
+ _ticks, _ticklabels, _label = False, False, False
1098
+ else:
1099
+ _ticks, _ticklabels, _label = None, None, None
1100
+
1101
+ if ticks is not None:
1102
+ _ticks = ticks
1103
+ if ticklabels is not None:
1104
+ _ticklabels = ticklabels
1105
+ if label is not None:
1106
+ _label = label
1107
+
1108
+ if _ticks is not None:
1109
+ self.major_ticks.set_visible(_ticks)
1110
+ self.minor_ticks.set_visible(_ticks)
1111
+ if _ticklabels is not None:
1112
+ self.major_ticklabels.set_visible(_ticklabels)
1113
+ self.minor_ticklabels.set_visible(_ticklabels)
1114
+ if _label is not None:
1115
+ self.label.set_visible(_label)
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axisline_style.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Provides classes to style the axis lines.
3
+ """
4
+ import math
5
+
6
+ import numpy as np
7
+
8
+ import matplotlib as mpl
9
+ from matplotlib.patches import _Style, FancyArrowPatch
10
+ from matplotlib.path import Path
11
+ from matplotlib.transforms import IdentityTransform
12
+
13
+
14
+ class _FancyAxislineStyle:
15
+ class SimpleArrow(FancyArrowPatch):
16
+ """The artist class that will be returned for SimpleArrow style."""
17
+ _ARROW_STYLE = "->"
18
+
19
+ def __init__(self, axis_artist, line_path, transform,
20
+ line_mutation_scale):
21
+ self._axis_artist = axis_artist
22
+ self._line_transform = transform
23
+ self._line_path = line_path
24
+ self._line_mutation_scale = line_mutation_scale
25
+
26
+ FancyArrowPatch.__init__(self,
27
+ path=self._line_path,
28
+ arrowstyle=self._ARROW_STYLE,
29
+ patchA=None,
30
+ patchB=None,
31
+ shrinkA=0.,
32
+ shrinkB=0.,
33
+ mutation_scale=line_mutation_scale,
34
+ mutation_aspect=None,
35
+ transform=IdentityTransform(),
36
+ )
37
+
38
+ def set_line_mutation_scale(self, scale):
39
+ self.set_mutation_scale(scale*self._line_mutation_scale)
40
+
41
+ def _extend_path(self, path, mutation_size=10):
42
+ """
43
+ Extend the path to make a room for drawing arrow.
44
+ """
45
+ (x0, y0), (x1, y1) = path.vertices[-2:]
46
+ theta = math.atan2(y1 - y0, x1 - x0)
47
+ x2 = x1 + math.cos(theta) * mutation_size
48
+ y2 = y1 + math.sin(theta) * mutation_size
49
+ if path.codes is None:
50
+ return Path(np.concatenate([path.vertices, [[x2, y2]]]))
51
+ else:
52
+ return Path(np.concatenate([path.vertices, [[x2, y2]]]),
53
+ np.concatenate([path.codes, [Path.LINETO]]))
54
+
55
+ def set_path(self, path):
56
+ self._line_path = path
57
+
58
+ def draw(self, renderer):
59
+ """
60
+ Draw the axis line.
61
+ 1) Transform the path to the display coordinate.
62
+ 2) Extend the path to make a room for arrow.
63
+ 3) Update the path of the FancyArrowPatch.
64
+ 4) Draw.
65
+ """
66
+ path_in_disp = self._line_transform.transform_path(self._line_path)
67
+ mutation_size = self.get_mutation_scale() # line_mutation_scale()
68
+ extended_path = self._extend_path(path_in_disp,
69
+ mutation_size=mutation_size)
70
+ self._path_original = extended_path
71
+ FancyArrowPatch.draw(self, renderer)
72
+
73
+ def get_window_extent(self, renderer=None):
74
+
75
+ path_in_disp = self._line_transform.transform_path(self._line_path)
76
+ mutation_size = self.get_mutation_scale() # line_mutation_scale()
77
+ extended_path = self._extend_path(path_in_disp,
78
+ mutation_size=mutation_size)
79
+ self._path_original = extended_path
80
+ return FancyArrowPatch.get_window_extent(self, renderer)
81
+
82
+ class FilledArrow(SimpleArrow):
83
+ """The artist class that will be returned for FilledArrow style."""
84
+ _ARROW_STYLE = "-|>"
85
+
86
+ def __init__(self, axis_artist, line_path, transform,
87
+ line_mutation_scale, facecolor):
88
+ super().__init__(axis_artist, line_path, transform,
89
+ line_mutation_scale)
90
+ self.set_facecolor(facecolor)
91
+
92
+
93
+ class AxislineStyle(_Style):
94
+ """
95
+ A container class which defines style classes for AxisArtists.
96
+
97
+ An instance of any axisline style class is a callable object,
98
+ whose call signature is ::
99
+
100
+ __call__(self, axis_artist, path, transform)
101
+
102
+ When called, this should return an `.Artist` with the following methods::
103
+
104
+ def set_path(self, path):
105
+ # set the path for axisline.
106
+
107
+ def set_line_mutation_scale(self, scale):
108
+ # set the scale
109
+
110
+ def draw(self, renderer):
111
+ # draw
112
+ """
113
+
114
+ _style_list = {}
115
+
116
+ class _Base:
117
+ # The derived classes are required to be able to be initialized
118
+ # w/o arguments, i.e., all its argument (except self) must have
119
+ # the default values.
120
+
121
+ def __init__(self):
122
+ """
123
+ initialization.
124
+ """
125
+ super().__init__()
126
+
127
+ def __call__(self, axis_artist, transform):
128
+ """
129
+ Given the AxisArtist instance, and transform for the path (set_path
130
+ method), return the Matplotlib artist for drawing the axis line.
131
+ """
132
+ return self.new_line(axis_artist, transform)
133
+
134
+ class SimpleArrow(_Base):
135
+ """
136
+ A simple arrow.
137
+ """
138
+
139
+ ArrowAxisClass = _FancyAxislineStyle.SimpleArrow
140
+
141
+ def __init__(self, size=1):
142
+ """
143
+ Parameters
144
+ ----------
145
+ size : float
146
+ Size of the arrow as a fraction of the ticklabel size.
147
+ """
148
+
149
+ self.size = size
150
+ super().__init__()
151
+
152
+ def new_line(self, axis_artist, transform):
153
+
154
+ linepath = Path([(0, 0), (0, 1)])
155
+ axisline = self.ArrowAxisClass(axis_artist, linepath, transform,
156
+ line_mutation_scale=self.size)
157
+ return axisline
158
+
159
+ _style_list["->"] = SimpleArrow
160
+
161
+ class FilledArrow(SimpleArrow):
162
+ """
163
+ An arrow with a filled head.
164
+ """
165
+
166
+ ArrowAxisClass = _FancyAxislineStyle.FilledArrow
167
+
168
+ def __init__(self, size=1, facecolor=None):
169
+ """
170
+ Parameters
171
+ ----------
172
+ size : float
173
+ Size of the arrow as a fraction of the ticklabel size.
174
+ facecolor : :mpltype:`color`, default: :rc:`axes.edgecolor`
175
+ Fill color.
176
+
177
+ .. versionadded:: 3.7
178
+ """
179
+
180
+ if facecolor is None:
181
+ facecolor = mpl.rcParams['axes.edgecolor']
182
+ self.size = size
183
+ self._facecolor = facecolor
184
+ super().__init__(size=size)
185
+
186
+ def new_line(self, axis_artist, transform):
187
+ linepath = Path([(0, 0), (0, 1)])
188
+ axisline = self.ArrowAxisClass(axis_artist, linepath, transform,
189
+ line_mutation_scale=self.size,
190
+ facecolor=self._facecolor)
191
+ return axisline
192
+
193
+ _style_list["-|>"] = FilledArrow
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/axislines.py ADDED
@@ -0,0 +1,479 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Axislines includes modified implementation of the Axes class. The
3
+ biggest difference is that the artists responsible for drawing the axis spine,
4
+ ticks, ticklabels and axis labels are separated out from Matplotlib's Axis
5
+ class. Originally, this change was motivated to support curvilinear
6
+ grid. Here are a few reasons that I came up with a new axes class:
7
+
8
+ * "top" and "bottom" x-axis (or "left" and "right" y-axis) can have
9
+ different ticks (tick locations and labels). This is not possible
10
+ with the current Matplotlib, although some twin axes trick can help.
11
+
12
+ * Curvilinear grid.
13
+
14
+ * angled ticks.
15
+
16
+ In the new axes class, xaxis and yaxis is set to not visible by
17
+ default, and new set of artist (AxisArtist) are defined to draw axis
18
+ line, ticks, ticklabels and axis label. Axes.axis attribute serves as
19
+ a dictionary of these artists, i.e., ax.axis["left"] is a AxisArtist
20
+ instance responsible to draw left y-axis. The default Axes.axis contains
21
+ "bottom", "left", "top" and "right".
22
+
23
+ AxisArtist can be considered as a container artist and has the following
24
+ children artists which will draw ticks, labels, etc.
25
+
26
+ * line
27
+ * major_ticks, major_ticklabels
28
+ * minor_ticks, minor_ticklabels
29
+ * offsetText
30
+ * label
31
+
32
+ Note that these are separate artists from `matplotlib.axis.Axis`, thus most
33
+ tick-related functions in Matplotlib won't work. For example, color and
34
+ markerwidth of the ``ax.axis["bottom"].major_ticks`` will follow those of
35
+ Axes.xaxis unless explicitly specified.
36
+
37
+ In addition to AxisArtist, the Axes will have *gridlines* attribute,
38
+ which obviously draws grid lines. The gridlines needs to be separated
39
+ from the axis as some gridlines can never pass any axis.
40
+ """
41
+
42
+ import numpy as np
43
+
44
+ import matplotlib as mpl
45
+ from matplotlib import _api
46
+ import matplotlib.axes as maxes
47
+ from matplotlib.path import Path
48
+ from mpl_toolkits.axes_grid1 import mpl_axes
49
+ from .axisline_style import AxislineStyle # noqa
50
+ from .axis_artist import AxisArtist, GridlinesCollection
51
+
52
+
53
+ class _AxisArtistHelperBase:
54
+ """
55
+ Base class for axis helper.
56
+
57
+ Subclasses should define the methods listed below. The *axes*
58
+ argument will be the ``.axes`` attribute of the caller artist. ::
59
+
60
+ # Construct the spine.
61
+
62
+ def get_line_transform(self, axes):
63
+ return transform
64
+
65
+ def get_line(self, axes):
66
+ return path
67
+
68
+ # Construct the label.
69
+
70
+ def get_axislabel_transform(self, axes):
71
+ return transform
72
+
73
+ def get_axislabel_pos_angle(self, axes):
74
+ return (x, y), angle
75
+
76
+ # Construct the ticks.
77
+
78
+ def get_tick_transform(self, axes):
79
+ return transform
80
+
81
+ def get_tick_iterators(self, axes):
82
+ # A pair of iterables (one for major ticks, one for minor ticks)
83
+ # that yield (tick_position, tick_angle, tick_label).
84
+ return iter_major, iter_minor
85
+ """
86
+
87
+ def __init__(self, nth_coord):
88
+ self.nth_coord = nth_coord
89
+
90
+ def update_lim(self, axes):
91
+ pass
92
+
93
+ def get_nth_coord(self):
94
+ return self.nth_coord
95
+
96
+ def _to_xy(self, values, const):
97
+ """
98
+ Create a (*values.shape, 2)-shape array representing (x, y) pairs.
99
+
100
+ The other coordinate is filled with the constant *const*.
101
+
102
+ Example::
103
+
104
+ >>> self.nth_coord = 0
105
+ >>> self._to_xy([1, 2, 3], const=0)
106
+ array([[1, 0],
107
+ [2, 0],
108
+ [3, 0]])
109
+ """
110
+ if self.nth_coord == 0:
111
+ return np.stack(np.broadcast_arrays(values, const), axis=-1)
112
+ elif self.nth_coord == 1:
113
+ return np.stack(np.broadcast_arrays(const, values), axis=-1)
114
+ else:
115
+ raise ValueError("Unexpected nth_coord")
116
+
117
+
118
+ class _FixedAxisArtistHelperBase(_AxisArtistHelperBase):
119
+ """Helper class for a fixed (in the axes coordinate) axis."""
120
+
121
+ @_api.delete_parameter("3.9", "nth_coord")
122
+ def __init__(self, loc, nth_coord=None):
123
+ """``nth_coord = 0``: x-axis; ``nth_coord = 1``: y-axis."""
124
+ super().__init__(_api.check_getitem(
125
+ {"bottom": 0, "top": 0, "left": 1, "right": 1}, loc=loc))
126
+ self._loc = loc
127
+ self._pos = {"bottom": 0, "top": 1, "left": 0, "right": 1}[loc]
128
+ # axis line in transAxes
129
+ self._path = Path(self._to_xy((0, 1), const=self._pos))
130
+
131
+ # LINE
132
+
133
+ def get_line(self, axes):
134
+ return self._path
135
+
136
+ def get_line_transform(self, axes):
137
+ return axes.transAxes
138
+
139
+ # LABEL
140
+
141
+ def get_axislabel_transform(self, axes):
142
+ return axes.transAxes
143
+
144
+ def get_axislabel_pos_angle(self, axes):
145
+ """
146
+ Return the label reference position in transAxes.
147
+
148
+ get_label_transform() returns a transform of (transAxes+offset)
149
+ """
150
+ return dict(left=((0., 0.5), 90), # (position, angle_tangent)
151
+ right=((1., 0.5), 90),
152
+ bottom=((0.5, 0.), 0),
153
+ top=((0.5, 1.), 0))[self._loc]
154
+
155
+ # TICK
156
+
157
+ def get_tick_transform(self, axes):
158
+ return [axes.get_xaxis_transform(), axes.get_yaxis_transform()][self.nth_coord]
159
+
160
+
161
+ class _FloatingAxisArtistHelperBase(_AxisArtistHelperBase):
162
+ def __init__(self, nth_coord, value):
163
+ self._value = value
164
+ super().__init__(nth_coord)
165
+
166
+ def get_line(self, axes):
167
+ raise RuntimeError("get_line method should be defined by the derived class")
168
+
169
+
170
+ class FixedAxisArtistHelperRectilinear(_FixedAxisArtistHelperBase):
171
+
172
+ @_api.delete_parameter("3.9", "nth_coord")
173
+ def __init__(self, axes, loc, nth_coord=None):
174
+ """
175
+ nth_coord = along which coordinate value varies
176
+ in 2D, nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
177
+ """
178
+ super().__init__(loc)
179
+ self.axis = [axes.xaxis, axes.yaxis][self.nth_coord]
180
+
181
+ # TICK
182
+
183
+ def get_tick_iterators(self, axes):
184
+ """tick_loc, tick_angle, tick_label"""
185
+ angle_normal, angle_tangent = {0: (90, 0), 1: (0, 90)}[self.nth_coord]
186
+
187
+ major = self.axis.major
188
+ major_locs = major.locator()
189
+ major_labels = major.formatter.format_ticks(major_locs)
190
+
191
+ minor = self.axis.minor
192
+ minor_locs = minor.locator()
193
+ minor_labels = minor.formatter.format_ticks(minor_locs)
194
+
195
+ tick_to_axes = self.get_tick_transform(axes) - axes.transAxes
196
+
197
+ def _f(locs, labels):
198
+ for loc, label in zip(locs, labels):
199
+ c = self._to_xy(loc, const=self._pos)
200
+ # check if the tick point is inside axes
201
+ c2 = tick_to_axes.transform(c)
202
+ if mpl.transforms._interval_contains_close((0, 1), c2[self.nth_coord]):
203
+ yield c, angle_normal, angle_tangent, label
204
+
205
+ return _f(major_locs, major_labels), _f(minor_locs, minor_labels)
206
+
207
+
208
+ class FloatingAxisArtistHelperRectilinear(_FloatingAxisArtistHelperBase):
209
+
210
+ def __init__(self, axes, nth_coord,
211
+ passingthrough_point, axis_direction="bottom"):
212
+ super().__init__(nth_coord, passingthrough_point)
213
+ self._axis_direction = axis_direction
214
+ self.axis = [axes.xaxis, axes.yaxis][self.nth_coord]
215
+
216
+ def get_line(self, axes):
217
+ fixed_coord = 1 - self.nth_coord
218
+ data_to_axes = axes.transData - axes.transAxes
219
+ p = data_to_axes.transform([self._value, self._value])
220
+ return Path(self._to_xy((0, 1), const=p[fixed_coord]))
221
+
222
+ def get_line_transform(self, axes):
223
+ return axes.transAxes
224
+
225
+ def get_axislabel_transform(self, axes):
226
+ return axes.transAxes
227
+
228
+ def get_axislabel_pos_angle(self, axes):
229
+ """
230
+ Return the label reference position in transAxes.
231
+
232
+ get_label_transform() returns a transform of (transAxes+offset)
233
+ """
234
+ angle = [0, 90][self.nth_coord]
235
+ fixed_coord = 1 - self.nth_coord
236
+ data_to_axes = axes.transData - axes.transAxes
237
+ p = data_to_axes.transform([self._value, self._value])
238
+ verts = self._to_xy(0.5, const=p[fixed_coord])
239
+ return (verts, angle) if 0 <= verts[fixed_coord] <= 1 else (None, None)
240
+
241
+ def get_tick_transform(self, axes):
242
+ return axes.transData
243
+
244
+ def get_tick_iterators(self, axes):
245
+ """tick_loc, tick_angle, tick_label"""
246
+ angle_normal, angle_tangent = {0: (90, 0), 1: (0, 90)}[self.nth_coord]
247
+
248
+ major = self.axis.major
249
+ major_locs = major.locator()
250
+ major_labels = major.formatter.format_ticks(major_locs)
251
+
252
+ minor = self.axis.minor
253
+ minor_locs = minor.locator()
254
+ minor_labels = minor.formatter.format_ticks(minor_locs)
255
+
256
+ data_to_axes = axes.transData - axes.transAxes
257
+
258
+ def _f(locs, labels):
259
+ for loc, label in zip(locs, labels):
260
+ c = self._to_xy(loc, const=self._value)
261
+ c1, c2 = data_to_axes.transform(c)
262
+ if 0 <= c1 <= 1 and 0 <= c2 <= 1:
263
+ yield c, angle_normal, angle_tangent, label
264
+
265
+ return _f(major_locs, major_labels), _f(minor_locs, minor_labels)
266
+
267
+
268
+ class AxisArtistHelper: # Backcompat.
269
+ Fixed = _FixedAxisArtistHelperBase
270
+ Floating = _FloatingAxisArtistHelperBase
271
+
272
+
273
+ class AxisArtistHelperRectlinear: # Backcompat.
274
+ Fixed = FixedAxisArtistHelperRectilinear
275
+ Floating = FloatingAxisArtistHelperRectilinear
276
+
277
+
278
+ class GridHelperBase:
279
+
280
+ def __init__(self):
281
+ self._old_limits = None
282
+ super().__init__()
283
+
284
+ def update_lim(self, axes):
285
+ x1, x2 = axes.get_xlim()
286
+ y1, y2 = axes.get_ylim()
287
+ if self._old_limits != (x1, x2, y1, y2):
288
+ self._update_grid(x1, y1, x2, y2)
289
+ self._old_limits = (x1, x2, y1, y2)
290
+
291
+ def _update_grid(self, x1, y1, x2, y2):
292
+ """Cache relevant computations when the axes limits have changed."""
293
+
294
+ def get_gridlines(self, which, axis):
295
+ """
296
+ Return list of grid lines as a list of paths (list of points).
297
+
298
+ Parameters
299
+ ----------
300
+ which : {"both", "major", "minor"}
301
+ axis : {"both", "x", "y"}
302
+ """
303
+ return []
304
+
305
+
306
+ class GridHelperRectlinear(GridHelperBase):
307
+
308
+ def __init__(self, axes):
309
+ super().__init__()
310
+ self.axes = axes
311
+
312
+ @_api.delete_parameter(
313
+ "3.9", "nth_coord", addendum="'nth_coord' is now inferred from 'loc'.")
314
+ def new_fixed_axis(
315
+ self, loc, nth_coord=None, axis_direction=None, offset=None, axes=None):
316
+ if axes is None:
317
+ _api.warn_external(
318
+ "'new_fixed_axis' explicitly requires the axes keyword.")
319
+ axes = self.axes
320
+ if axis_direction is None:
321
+ axis_direction = loc
322
+ return AxisArtist(axes, FixedAxisArtistHelperRectilinear(axes, loc),
323
+ offset=offset, axis_direction=axis_direction)
324
+
325
+ def new_floating_axis(self, nth_coord, value, axis_direction="bottom", axes=None):
326
+ if axes is None:
327
+ _api.warn_external(
328
+ "'new_floating_axis' explicitly requires the axes keyword.")
329
+ axes = self.axes
330
+ helper = FloatingAxisArtistHelperRectilinear(
331
+ axes, nth_coord, value, axis_direction)
332
+ axisline = AxisArtist(axes, helper, axis_direction=axis_direction)
333
+ axisline.line.set_clip_on(True)
334
+ axisline.line.set_clip_box(axisline.axes.bbox)
335
+ return axisline
336
+
337
+ def get_gridlines(self, which="major", axis="both"):
338
+ """
339
+ Return list of gridline coordinates in data coordinates.
340
+
341
+ Parameters
342
+ ----------
343
+ which : {"both", "major", "minor"}
344
+ axis : {"both", "x", "y"}
345
+ """
346
+ _api.check_in_list(["both", "major", "minor"], which=which)
347
+ _api.check_in_list(["both", "x", "y"], axis=axis)
348
+ gridlines = []
349
+
350
+ if axis in ("both", "x"):
351
+ locs = []
352
+ y1, y2 = self.axes.get_ylim()
353
+ if which in ("both", "major"):
354
+ locs.extend(self.axes.xaxis.major.locator())
355
+ if which in ("both", "minor"):
356
+ locs.extend(self.axes.xaxis.minor.locator())
357
+ gridlines.extend([[x, x], [y1, y2]] for x in locs)
358
+
359
+ if axis in ("both", "y"):
360
+ x1, x2 = self.axes.get_xlim()
361
+ locs = []
362
+ if self.axes.yaxis._major_tick_kw["gridOn"]:
363
+ locs.extend(self.axes.yaxis.major.locator())
364
+ if self.axes.yaxis._minor_tick_kw["gridOn"]:
365
+ locs.extend(self.axes.yaxis.minor.locator())
366
+ gridlines.extend([[x1, x2], [y, y]] for y in locs)
367
+
368
+ return gridlines
369
+
370
+
371
+ class Axes(maxes.Axes):
372
+
373
+ def __init__(self, *args, grid_helper=None, **kwargs):
374
+ self._axisline_on = True
375
+ self._grid_helper = grid_helper if grid_helper else GridHelperRectlinear(self)
376
+ super().__init__(*args, **kwargs)
377
+ self.toggle_axisline(True)
378
+
379
+ def toggle_axisline(self, b=None):
380
+ if b is None:
381
+ b = not self._axisline_on
382
+ if b:
383
+ self._axisline_on = True
384
+ self.spines[:].set_visible(False)
385
+ self.xaxis.set_visible(False)
386
+ self.yaxis.set_visible(False)
387
+ else:
388
+ self._axisline_on = False
389
+ self.spines[:].set_visible(True)
390
+ self.xaxis.set_visible(True)
391
+ self.yaxis.set_visible(True)
392
+
393
+ @property
394
+ def axis(self):
395
+ return self._axislines
396
+
397
+ def clear(self):
398
+ # docstring inherited
399
+
400
+ # Init gridlines before clear() as clear() calls grid().
401
+ self.gridlines = gridlines = GridlinesCollection(
402
+ [],
403
+ colors=mpl.rcParams['grid.color'],
404
+ linestyles=mpl.rcParams['grid.linestyle'],
405
+ linewidths=mpl.rcParams['grid.linewidth'])
406
+ self._set_artist_props(gridlines)
407
+ gridlines.set_grid_helper(self.get_grid_helper())
408
+
409
+ super().clear()
410
+
411
+ # clip_path is set after Axes.clear(): that's when a patch is created.
412
+ gridlines.set_clip_path(self.axes.patch)
413
+
414
+ # Init axis artists.
415
+ self._axislines = mpl_axes.Axes.AxisDict(self)
416
+ new_fixed_axis = self.get_grid_helper().new_fixed_axis
417
+ self._axislines.update({
418
+ loc: new_fixed_axis(loc=loc, axes=self, axis_direction=loc)
419
+ for loc in ["bottom", "top", "left", "right"]})
420
+ for axisline in [self._axislines["top"], self._axislines["right"]]:
421
+ axisline.label.set_visible(False)
422
+ axisline.major_ticklabels.set_visible(False)
423
+ axisline.minor_ticklabels.set_visible(False)
424
+
425
+ def get_grid_helper(self):
426
+ return self._grid_helper
427
+
428
+ def grid(self, visible=None, which='major', axis="both", **kwargs):
429
+ """
430
+ Toggle the gridlines, and optionally set the properties of the lines.
431
+ """
432
+ # There are some discrepancies in the behavior of grid() between
433
+ # axes_grid and Matplotlib, because axes_grid explicitly sets the
434
+ # visibility of the gridlines.
435
+ super().grid(visible, which=which, axis=axis, **kwargs)
436
+ if not self._axisline_on:
437
+ return
438
+ if visible is None:
439
+ visible = (self.axes.xaxis._minor_tick_kw["gridOn"]
440
+ or self.axes.xaxis._major_tick_kw["gridOn"]
441
+ or self.axes.yaxis._minor_tick_kw["gridOn"]
442
+ or self.axes.yaxis._major_tick_kw["gridOn"])
443
+ self.gridlines.set(which=which, axis=axis, visible=visible)
444
+ self.gridlines.set(**kwargs)
445
+
446
+ def get_children(self):
447
+ if self._axisline_on:
448
+ children = [*self._axislines.values(), self.gridlines]
449
+ else:
450
+ children = []
451
+ children.extend(super().get_children())
452
+ return children
453
+
454
+ def new_fixed_axis(self, loc, offset=None):
455
+ return self.get_grid_helper().new_fixed_axis(loc, offset=offset, axes=self)
456
+
457
+ def new_floating_axis(self, nth_coord, value, axis_direction="bottom"):
458
+ return self.get_grid_helper().new_floating_axis(
459
+ nth_coord, value, axis_direction=axis_direction, axes=self)
460
+
461
+
462
+ class AxesZero(Axes):
463
+
464
+ def clear(self):
465
+ super().clear()
466
+ new_floating_axis = self.get_grid_helper().new_floating_axis
467
+ self._axislines.update(
468
+ xzero=new_floating_axis(
469
+ nth_coord=0, value=0., axis_direction="bottom", axes=self),
470
+ yzero=new_floating_axis(
471
+ nth_coord=1, value=0., axis_direction="left", axes=self),
472
+ )
473
+ for k in ["xzero", "yzero"]:
474
+ self._axislines[k].line.set_clip_path(self.patch)
475
+ self._axislines[k].set_visible(False)
476
+
477
+
478
+ Subplot = Axes
479
+ SubplotZero = AxesZero
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/floating_axes.py ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ An experimental support for curvilinear grid.
3
+ """
4
+
5
+ # TODO :
6
+ # see if tick_iterator method can be simplified by reusing the parent method.
7
+
8
+ import functools
9
+
10
+ import numpy as np
11
+
12
+ import matplotlib as mpl
13
+ from matplotlib import _api, cbook
14
+ import matplotlib.patches as mpatches
15
+ from matplotlib.path import Path
16
+
17
+ from mpl_toolkits.axes_grid1.parasite_axes import host_axes_class_factory
18
+
19
+ from . import axislines, grid_helper_curvelinear
20
+ from .axis_artist import AxisArtist
21
+ from .grid_finder import ExtremeFinderSimple
22
+
23
+
24
+ class FloatingAxisArtistHelper(
25
+ grid_helper_curvelinear.FloatingAxisArtistHelper):
26
+ pass
27
+
28
+
29
+ class FixedAxisArtistHelper(grid_helper_curvelinear.FloatingAxisArtistHelper):
30
+
31
+ def __init__(self, grid_helper, side, nth_coord_ticks=None):
32
+ """
33
+ nth_coord = along which coordinate value varies.
34
+ nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
35
+ """
36
+ lon1, lon2, lat1, lat2 = grid_helper.grid_finder.extreme_finder(*[None] * 5)
37
+ value, nth_coord = _api.check_getitem(
38
+ dict(left=(lon1, 0), right=(lon2, 0), bottom=(lat1, 1), top=(lat2, 1)),
39
+ side=side)
40
+ super().__init__(grid_helper, nth_coord, value, axis_direction=side)
41
+ if nth_coord_ticks is None:
42
+ nth_coord_ticks = nth_coord
43
+ self.nth_coord_ticks = nth_coord_ticks
44
+
45
+ self.value = value
46
+ self.grid_helper = grid_helper
47
+ self._side = side
48
+
49
+ def update_lim(self, axes):
50
+ self.grid_helper.update_lim(axes)
51
+ self._grid_info = self.grid_helper._grid_info
52
+
53
+ def get_tick_iterators(self, axes):
54
+ """tick_loc, tick_angle, tick_label, (optionally) tick_label"""
55
+
56
+ grid_finder = self.grid_helper.grid_finder
57
+
58
+ lat_levs, lat_n, lat_factor = self._grid_info["lat_info"]
59
+ yy0 = lat_levs / lat_factor
60
+
61
+ lon_levs, lon_n, lon_factor = self._grid_info["lon_info"]
62
+ xx0 = lon_levs / lon_factor
63
+
64
+ extremes = self.grid_helper.grid_finder.extreme_finder(*[None] * 5)
65
+ xmin, xmax = sorted(extremes[:2])
66
+ ymin, ymax = sorted(extremes[2:])
67
+
68
+ def trf_xy(x, y):
69
+ trf = grid_finder.get_transform() + axes.transData
70
+ return trf.transform(np.column_stack(np.broadcast_arrays(x, y))).T
71
+
72
+ if self.nth_coord == 0:
73
+ mask = (ymin <= yy0) & (yy0 <= ymax)
74
+ (xx1, yy1), (dxx1, dyy1), (dxx2, dyy2) = \
75
+ grid_helper_curvelinear._value_and_jacobian(
76
+ trf_xy, self.value, yy0[mask], (xmin, xmax), (ymin, ymax))
77
+ labels = self._grid_info["lat_labels"]
78
+
79
+ elif self.nth_coord == 1:
80
+ mask = (xmin <= xx0) & (xx0 <= xmax)
81
+ (xx1, yy1), (dxx2, dyy2), (dxx1, dyy1) = \
82
+ grid_helper_curvelinear._value_and_jacobian(
83
+ trf_xy, xx0[mask], self.value, (xmin, xmax), (ymin, ymax))
84
+ labels = self._grid_info["lon_labels"]
85
+
86
+ labels = [l for l, m in zip(labels, mask) if m]
87
+
88
+ angle_normal = np.arctan2(dyy1, dxx1)
89
+ angle_tangent = np.arctan2(dyy2, dxx2)
90
+ mm = (dyy1 == 0) & (dxx1 == 0) # points with degenerate normal
91
+ angle_normal[mm] = angle_tangent[mm] + np.pi / 2
92
+
93
+ tick_to_axes = self.get_tick_transform(axes) - axes.transAxes
94
+ in_01 = functools.partial(
95
+ mpl.transforms._interval_contains_close, (0, 1))
96
+
97
+ def f1():
98
+ for x, y, normal, tangent, lab \
99
+ in zip(xx1, yy1, angle_normal, angle_tangent, labels):
100
+ c2 = tick_to_axes.transform((x, y))
101
+ if in_01(c2[0]) and in_01(c2[1]):
102
+ yield [x, y], *np.rad2deg([normal, tangent]), lab
103
+
104
+ return f1(), iter([])
105
+
106
+ def get_line(self, axes):
107
+ self.update_lim(axes)
108
+ k, v = dict(left=("lon_lines0", 0),
109
+ right=("lon_lines0", 1),
110
+ bottom=("lat_lines0", 0),
111
+ top=("lat_lines0", 1))[self._side]
112
+ xx, yy = self._grid_info[k][v]
113
+ return Path(np.column_stack([xx, yy]))
114
+
115
+
116
+ class ExtremeFinderFixed(ExtremeFinderSimple):
117
+ # docstring inherited
118
+
119
+ def __init__(self, extremes):
120
+ """
121
+ This subclass always returns the same bounding box.
122
+
123
+ Parameters
124
+ ----------
125
+ extremes : (float, float, float, float)
126
+ The bounding box that this helper always returns.
127
+ """
128
+ self._extremes = extremes
129
+
130
+ def __call__(self, transform_xy, x1, y1, x2, y2):
131
+ # docstring inherited
132
+ return self._extremes
133
+
134
+
135
+ class GridHelperCurveLinear(grid_helper_curvelinear.GridHelperCurveLinear):
136
+
137
+ def __init__(self, aux_trans, extremes,
138
+ grid_locator1=None,
139
+ grid_locator2=None,
140
+ tick_formatter1=None,
141
+ tick_formatter2=None):
142
+ # docstring inherited
143
+ super().__init__(aux_trans,
144
+ extreme_finder=ExtremeFinderFixed(extremes),
145
+ grid_locator1=grid_locator1,
146
+ grid_locator2=grid_locator2,
147
+ tick_formatter1=tick_formatter1,
148
+ tick_formatter2=tick_formatter2)
149
+
150
+ def new_fixed_axis(
151
+ self, loc, nth_coord=None, axis_direction=None, offset=None, axes=None):
152
+ if axes is None:
153
+ axes = self.axes
154
+ if axis_direction is None:
155
+ axis_direction = loc
156
+ # This is not the same as the FixedAxisArtistHelper class used by
157
+ # grid_helper_curvelinear.GridHelperCurveLinear.new_fixed_axis!
158
+ helper = FixedAxisArtistHelper(
159
+ self, loc, nth_coord_ticks=nth_coord)
160
+ axisline = AxisArtist(axes, helper, axis_direction=axis_direction)
161
+ # Perhaps should be moved to the base class?
162
+ axisline.line.set_clip_on(True)
163
+ axisline.line.set_clip_box(axisline.axes.bbox)
164
+ return axisline
165
+
166
+ # new_floating_axis will inherit the grid_helper's extremes.
167
+
168
+ # def new_floating_axis(self, nth_coord, value, axes=None, axis_direction="bottom"):
169
+ # axis = super(GridHelperCurveLinear,
170
+ # self).new_floating_axis(nth_coord,
171
+ # value, axes=axes,
172
+ # axis_direction=axis_direction)
173
+ # # set extreme values of the axis helper
174
+ # if nth_coord == 1:
175
+ # axis.get_helper().set_extremes(*self._extremes[:2])
176
+ # elif nth_coord == 0:
177
+ # axis.get_helper().set_extremes(*self._extremes[2:])
178
+ # return axis
179
+
180
+ def _update_grid(self, x1, y1, x2, y2):
181
+ if self._grid_info is None:
182
+ self._grid_info = dict()
183
+
184
+ grid_info = self._grid_info
185
+
186
+ grid_finder = self.grid_finder
187
+ extremes = grid_finder.extreme_finder(grid_finder.inv_transform_xy,
188
+ x1, y1, x2, y2)
189
+
190
+ lon_min, lon_max = sorted(extremes[:2])
191
+ lat_min, lat_max = sorted(extremes[2:])
192
+ grid_info["extremes"] = lon_min, lon_max, lat_min, lat_max # extremes
193
+
194
+ lon_levs, lon_n, lon_factor = \
195
+ grid_finder.grid_locator1(lon_min, lon_max)
196
+ lon_levs = np.asarray(lon_levs)
197
+ lat_levs, lat_n, lat_factor = \
198
+ grid_finder.grid_locator2(lat_min, lat_max)
199
+ lat_levs = np.asarray(lat_levs)
200
+
201
+ grid_info["lon_info"] = lon_levs, lon_n, lon_factor
202
+ grid_info["lat_info"] = lat_levs, lat_n, lat_factor
203
+
204
+ grid_info["lon_labels"] = grid_finder._format_ticks(
205
+ 1, "bottom", lon_factor, lon_levs)
206
+ grid_info["lat_labels"] = grid_finder._format_ticks(
207
+ 2, "bottom", lat_factor, lat_levs)
208
+
209
+ lon_values = lon_levs[:lon_n] / lon_factor
210
+ lat_values = lat_levs[:lat_n] / lat_factor
211
+
212
+ lon_lines, lat_lines = grid_finder._get_raw_grid_lines(
213
+ lon_values[(lon_min < lon_values) & (lon_values < lon_max)],
214
+ lat_values[(lat_min < lat_values) & (lat_values < lat_max)],
215
+ lon_min, lon_max, lat_min, lat_max)
216
+
217
+ grid_info["lon_lines"] = lon_lines
218
+ grid_info["lat_lines"] = lat_lines
219
+
220
+ lon_lines, lat_lines = grid_finder._get_raw_grid_lines(
221
+ # lon_min, lon_max, lat_min, lat_max)
222
+ extremes[:2], extremes[2:], *extremes)
223
+
224
+ grid_info["lon_lines0"] = lon_lines
225
+ grid_info["lat_lines0"] = lat_lines
226
+
227
+ def get_gridlines(self, which="major", axis="both"):
228
+ grid_lines = []
229
+ if axis in ["both", "x"]:
230
+ grid_lines.extend(self._grid_info["lon_lines"])
231
+ if axis in ["both", "y"]:
232
+ grid_lines.extend(self._grid_info["lat_lines"])
233
+ return grid_lines
234
+
235
+
236
+ class FloatingAxesBase:
237
+
238
+ def __init__(self, *args, grid_helper, **kwargs):
239
+ _api.check_isinstance(GridHelperCurveLinear, grid_helper=grid_helper)
240
+ super().__init__(*args, grid_helper=grid_helper, **kwargs)
241
+ self.set_aspect(1.)
242
+
243
+ def _gen_axes_patch(self):
244
+ # docstring inherited
245
+ x0, x1, y0, y1 = self.get_grid_helper().grid_finder.extreme_finder(*[None] * 5)
246
+ patch = mpatches.Polygon([(x0, y0), (x1, y0), (x1, y1), (x0, y1)])
247
+ patch.get_path()._interpolation_steps = 100
248
+ return patch
249
+
250
+ def clear(self):
251
+ super().clear()
252
+ self.patch.set_transform(
253
+ self.get_grid_helper().grid_finder.get_transform()
254
+ + self.transData)
255
+ # The original patch is not in the draw tree; it is only used for
256
+ # clipping purposes.
257
+ orig_patch = super()._gen_axes_patch()
258
+ orig_patch.set_figure(self.get_figure(root=False))
259
+ orig_patch.set_transform(self.transAxes)
260
+ self.patch.set_clip_path(orig_patch)
261
+ self.gridlines.set_clip_path(orig_patch)
262
+ self.adjust_axes_lim()
263
+
264
+ def adjust_axes_lim(self):
265
+ bbox = self.patch.get_path().get_extents(
266
+ # First transform to pixel coords, then to parent data coords.
267
+ self.patch.get_transform() - self.transData)
268
+ bbox = bbox.expanded(1.02, 1.02)
269
+ self.set_xlim(bbox.xmin, bbox.xmax)
270
+ self.set_ylim(bbox.ymin, bbox.ymax)
271
+
272
+
273
+ floatingaxes_class_factory = cbook._make_class_factory(FloatingAxesBase, "Floating{}")
274
+ FloatingAxes = floatingaxes_class_factory(host_axes_class_factory(axislines.Axes))
275
+ FloatingSubplot = FloatingAxes
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/grid_finder.py ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from matplotlib import ticker as mticker, _api
4
+ from matplotlib.transforms import Bbox, Transform
5
+
6
+
7
+ def _find_line_box_crossings(xys, bbox):
8
+ """
9
+ Find the points where a polyline crosses a bbox, and the crossing angles.
10
+
11
+ Parameters
12
+ ----------
13
+ xys : (N, 2) array
14
+ The polyline coordinates.
15
+ bbox : `.Bbox`
16
+ The bounding box.
17
+
18
+ Returns
19
+ -------
20
+ list of ((float, float), float)
21
+ Four separate lists of crossings, for the left, right, bottom, and top
22
+ sides of the bbox, respectively. For each list, the entries are the
23
+ ``((x, y), ccw_angle_in_degrees)`` of the crossing, where an angle of 0
24
+ means that the polyline is moving to the right at the crossing point.
25
+
26
+ The entries are computed by linearly interpolating at each crossing
27
+ between the nearest points on either side of the bbox edges.
28
+ """
29
+ crossings = []
30
+ dxys = xys[1:] - xys[:-1]
31
+ for sl in [slice(None), slice(None, None, -1)]:
32
+ us, vs = xys.T[sl] # "this" coord, "other" coord
33
+ dus, dvs = dxys.T[sl]
34
+ umin, vmin = bbox.min[sl]
35
+ umax, vmax = bbox.max[sl]
36
+ for u0, inside in [(umin, us > umin), (umax, us < umax)]:
37
+ cross = []
38
+ idxs, = (inside[:-1] ^ inside[1:]).nonzero()
39
+ for idx in idxs:
40
+ v = vs[idx] + (u0 - us[idx]) * dvs[idx] / dus[idx]
41
+ if not vmin <= v <= vmax:
42
+ continue
43
+ crossing = (u0, v)[sl]
44
+ theta = np.degrees(np.arctan2(*dxys[idx][::-1]))
45
+ cross.append((crossing, theta))
46
+ crossings.append(cross)
47
+ return crossings
48
+
49
+
50
+ class ExtremeFinderSimple:
51
+ """
52
+ A helper class to figure out the range of grid lines that need to be drawn.
53
+ """
54
+
55
+ def __init__(self, nx, ny):
56
+ """
57
+ Parameters
58
+ ----------
59
+ nx, ny : int
60
+ The number of samples in each direction.
61
+ """
62
+ self.nx = nx
63
+ self.ny = ny
64
+
65
+ def __call__(self, transform_xy, x1, y1, x2, y2):
66
+ """
67
+ Compute an approximation of the bounding box obtained by applying
68
+ *transform_xy* to the box delimited by ``(x1, y1, x2, y2)``.
69
+
70
+ The intended use is to have ``(x1, y1, x2, y2)`` in axes coordinates,
71
+ and have *transform_xy* be the transform from axes coordinates to data
72
+ coordinates; this method then returns the range of data coordinates
73
+ that span the actual axes.
74
+
75
+ The computation is done by sampling ``nx * ny`` equispaced points in
76
+ the ``(x1, y1, x2, y2)`` box and finding the resulting points with
77
+ extremal coordinates; then adding some padding to take into account the
78
+ finite sampling.
79
+
80
+ As each sampling step covers a relative range of *1/nx* or *1/ny*,
81
+ the padding is computed by expanding the span covered by the extremal
82
+ coordinates by these fractions.
83
+ """
84
+ x, y = np.meshgrid(
85
+ np.linspace(x1, x2, self.nx), np.linspace(y1, y2, self.ny))
86
+ xt, yt = transform_xy(np.ravel(x), np.ravel(y))
87
+ return self._add_pad(xt.min(), xt.max(), yt.min(), yt.max())
88
+
89
+ def _add_pad(self, x_min, x_max, y_min, y_max):
90
+ """Perform the padding mentioned in `__call__`."""
91
+ dx = (x_max - x_min) / self.nx
92
+ dy = (y_max - y_min) / self.ny
93
+ return x_min - dx, x_max + dx, y_min - dy, y_max + dy
94
+
95
+
96
+ class _User2DTransform(Transform):
97
+ """A transform defined by two user-set functions."""
98
+
99
+ input_dims = output_dims = 2
100
+
101
+ def __init__(self, forward, backward):
102
+ """
103
+ Parameters
104
+ ----------
105
+ forward, backward : callable
106
+ The forward and backward transforms, taking ``x`` and ``y`` as
107
+ separate arguments and returning ``(tr_x, tr_y)``.
108
+ """
109
+ # The normal Matplotlib convention would be to take and return an
110
+ # (N, 2) array but axisartist uses the transposed version.
111
+ super().__init__()
112
+ self._forward = forward
113
+ self._backward = backward
114
+
115
+ def transform_non_affine(self, values):
116
+ # docstring inherited
117
+ return np.transpose(self._forward(*np.transpose(values)))
118
+
119
+ def inverted(self):
120
+ # docstring inherited
121
+ return type(self)(self._backward, self._forward)
122
+
123
+
124
+ class GridFinder:
125
+ """
126
+ Internal helper for `~.grid_helper_curvelinear.GridHelperCurveLinear`, with
127
+ the same constructor parameters; should not be directly instantiated.
128
+ """
129
+
130
+ def __init__(self,
131
+ transform,
132
+ extreme_finder=None,
133
+ grid_locator1=None,
134
+ grid_locator2=None,
135
+ tick_formatter1=None,
136
+ tick_formatter2=None):
137
+ if extreme_finder is None:
138
+ extreme_finder = ExtremeFinderSimple(20, 20)
139
+ if grid_locator1 is None:
140
+ grid_locator1 = MaxNLocator()
141
+ if grid_locator2 is None:
142
+ grid_locator2 = MaxNLocator()
143
+ if tick_formatter1 is None:
144
+ tick_formatter1 = FormatterPrettyPrint()
145
+ if tick_formatter2 is None:
146
+ tick_formatter2 = FormatterPrettyPrint()
147
+ self.extreme_finder = extreme_finder
148
+ self.grid_locator1 = grid_locator1
149
+ self.grid_locator2 = grid_locator2
150
+ self.tick_formatter1 = tick_formatter1
151
+ self.tick_formatter2 = tick_formatter2
152
+ self.set_transform(transform)
153
+
154
+ def _format_ticks(self, idx, direction, factor, levels):
155
+ """
156
+ Helper to support both standard formatters (inheriting from
157
+ `.mticker.Formatter`) and axisartist-specific ones; should be called instead of
158
+ directly calling ``self.tick_formatter1`` and ``self.tick_formatter2``. This
159
+ method should be considered as a temporary workaround which will be removed in
160
+ the future at the same time as axisartist-specific formatters.
161
+ """
162
+ fmt = _api.check_getitem(
163
+ {1: self.tick_formatter1, 2: self.tick_formatter2}, idx=idx)
164
+ return (fmt.format_ticks(levels) if isinstance(fmt, mticker.Formatter)
165
+ else fmt(direction, factor, levels))
166
+
167
+ def get_grid_info(self, x1, y1, x2, y2):
168
+ """
169
+ lon_values, lat_values : list of grid values. if integer is given,
170
+ rough number of grids in each direction.
171
+ """
172
+
173
+ extremes = self.extreme_finder(self.inv_transform_xy, x1, y1, x2, y2)
174
+
175
+ # min & max rage of lat (or lon) for each grid line will be drawn.
176
+ # i.e., gridline of lon=0 will be drawn from lat_min to lat_max.
177
+
178
+ lon_min, lon_max, lat_min, lat_max = extremes
179
+ lon_levs, lon_n, lon_factor = self.grid_locator1(lon_min, lon_max)
180
+ lon_levs = np.asarray(lon_levs)
181
+ lat_levs, lat_n, lat_factor = self.grid_locator2(lat_min, lat_max)
182
+ lat_levs = np.asarray(lat_levs)
183
+
184
+ lon_values = lon_levs[:lon_n] / lon_factor
185
+ lat_values = lat_levs[:lat_n] / lat_factor
186
+
187
+ lon_lines, lat_lines = self._get_raw_grid_lines(lon_values,
188
+ lat_values,
189
+ lon_min, lon_max,
190
+ lat_min, lat_max)
191
+
192
+ bb = Bbox.from_extents(x1, y1, x2, y2).expanded(1 + 2e-10, 1 + 2e-10)
193
+
194
+ grid_info = {
195
+ "extremes": extremes,
196
+ # "lon", "lat", filled below.
197
+ }
198
+
199
+ for idx, lon_or_lat, levs, factor, values, lines in [
200
+ (1, "lon", lon_levs, lon_factor, lon_values, lon_lines),
201
+ (2, "lat", lat_levs, lat_factor, lat_values, lat_lines),
202
+ ]:
203
+ grid_info[lon_or_lat] = gi = {
204
+ "lines": [[l] for l in lines],
205
+ "ticks": {"left": [], "right": [], "bottom": [], "top": []},
206
+ }
207
+ for (lx, ly), v, level in zip(lines, values, levs):
208
+ all_crossings = _find_line_box_crossings(np.column_stack([lx, ly]), bb)
209
+ for side, crossings in zip(
210
+ ["left", "right", "bottom", "top"], all_crossings):
211
+ for crossing in crossings:
212
+ gi["ticks"][side].append({"level": level, "loc": crossing})
213
+ for side in gi["ticks"]:
214
+ levs = [tick["level"] for tick in gi["ticks"][side]]
215
+ labels = self._format_ticks(idx, side, factor, levs)
216
+ for tick, label in zip(gi["ticks"][side], labels):
217
+ tick["label"] = label
218
+
219
+ return grid_info
220
+
221
+ def _get_raw_grid_lines(self,
222
+ lon_values, lat_values,
223
+ lon_min, lon_max, lat_min, lat_max):
224
+
225
+ lons_i = np.linspace(lon_min, lon_max, 100) # for interpolation
226
+ lats_i = np.linspace(lat_min, lat_max, 100)
227
+
228
+ lon_lines = [self.transform_xy(np.full_like(lats_i, lon), lats_i)
229
+ for lon in lon_values]
230
+ lat_lines = [self.transform_xy(lons_i, np.full_like(lons_i, lat))
231
+ for lat in lat_values]
232
+
233
+ return lon_lines, lat_lines
234
+
235
+ def set_transform(self, aux_trans):
236
+ if isinstance(aux_trans, Transform):
237
+ self._aux_transform = aux_trans
238
+ elif len(aux_trans) == 2 and all(map(callable, aux_trans)):
239
+ self._aux_transform = _User2DTransform(*aux_trans)
240
+ else:
241
+ raise TypeError("'aux_trans' must be either a Transform "
242
+ "instance or a pair of callables")
243
+
244
+ def get_transform(self):
245
+ return self._aux_transform
246
+
247
+ update_transform = set_transform # backcompat alias.
248
+
249
+ def transform_xy(self, x, y):
250
+ return self._aux_transform.transform(np.column_stack([x, y])).T
251
+
252
+ def inv_transform_xy(self, x, y):
253
+ return self._aux_transform.inverted().transform(
254
+ np.column_stack([x, y])).T
255
+
256
+ def update(self, **kwargs):
257
+ for k, v in kwargs.items():
258
+ if k in ["extreme_finder",
259
+ "grid_locator1",
260
+ "grid_locator2",
261
+ "tick_formatter1",
262
+ "tick_formatter2"]:
263
+ setattr(self, k, v)
264
+ else:
265
+ raise ValueError(f"Unknown update property {k!r}")
266
+
267
+
268
+ class MaxNLocator(mticker.MaxNLocator):
269
+ def __init__(self, nbins=10, steps=None,
270
+ trim=True,
271
+ integer=False,
272
+ symmetric=False,
273
+ prune=None):
274
+ # trim argument has no effect. It has been left for API compatibility
275
+ super().__init__(nbins, steps=steps, integer=integer,
276
+ symmetric=symmetric, prune=prune)
277
+ self.create_dummy_axis()
278
+
279
+ def __call__(self, v1, v2):
280
+ locs = super().tick_values(v1, v2)
281
+ return np.array(locs), len(locs), 1 # 1: factor (see angle_helper)
282
+
283
+
284
+ class FixedLocator:
285
+ def __init__(self, locs):
286
+ self._locs = locs
287
+
288
+ def __call__(self, v1, v2):
289
+ v1, v2 = sorted([v1, v2])
290
+ locs = np.array([l for l in self._locs if v1 <= l <= v2])
291
+ return locs, len(locs), 1 # 1: factor (see angle_helper)
292
+
293
+
294
+ # Tick Formatter
295
+
296
+ class FormatterPrettyPrint:
297
+ def __init__(self, useMathText=True):
298
+ self._fmt = mticker.ScalarFormatter(
299
+ useMathText=useMathText, useOffset=False)
300
+ self._fmt.create_dummy_axis()
301
+
302
+ def __call__(self, direction, factor, values):
303
+ return self._fmt.format_ticks(values)
304
+
305
+
306
+ class DictFormatter:
307
+ def __init__(self, format_dict, formatter=None):
308
+ """
309
+ format_dict : dictionary for format strings to be used.
310
+ formatter : fall-back formatter
311
+ """
312
+ super().__init__()
313
+ self._format_dict = format_dict
314
+ self._fallback_formatter = formatter
315
+
316
+ def __call__(self, direction, factor, values):
317
+ """
318
+ factor is ignored if value is found in the dictionary
319
+ """
320
+ if self._fallback_formatter:
321
+ fallback_strings = self._fallback_formatter(
322
+ direction, factor, values)
323
+ else:
324
+ fallback_strings = [""] * len(values)
325
+ return [self._format_dict.get(k, v)
326
+ for k, v in zip(values, fallback_strings)]
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.py ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ An experimental support for curvilinear grid.
3
+ """
4
+
5
+ import functools
6
+
7
+ import numpy as np
8
+
9
+ import matplotlib as mpl
10
+ from matplotlib import _api
11
+ from matplotlib.path import Path
12
+ from matplotlib.transforms import Affine2D, IdentityTransform
13
+ from .axislines import (
14
+ _FixedAxisArtistHelperBase, _FloatingAxisArtistHelperBase, GridHelperBase)
15
+ from .axis_artist import AxisArtist
16
+ from .grid_finder import GridFinder
17
+
18
+
19
+ def _value_and_jacobian(func, xs, ys, xlims, ylims):
20
+ """
21
+ Compute *func* and its derivatives along x and y at positions *xs*, *ys*,
22
+ while ensuring that finite difference calculations don't try to evaluate
23
+ values outside of *xlims*, *ylims*.
24
+ """
25
+ eps = np.finfo(float).eps ** (1/2) # see e.g. scipy.optimize.approx_fprime
26
+ val = func(xs, ys)
27
+ # Take the finite difference step in the direction where the bound is the
28
+ # furthest; the step size is min of epsilon and distance to that bound.
29
+ xlo, xhi = sorted(xlims)
30
+ dxlo = xs - xlo
31
+ dxhi = xhi - xs
32
+ xeps = (np.take([-1, 1], dxhi >= dxlo)
33
+ * np.minimum(eps, np.maximum(dxlo, dxhi)))
34
+ val_dx = func(xs + xeps, ys)
35
+ ylo, yhi = sorted(ylims)
36
+ dylo = ys - ylo
37
+ dyhi = yhi - ys
38
+ yeps = (np.take([-1, 1], dyhi >= dylo)
39
+ * np.minimum(eps, np.maximum(dylo, dyhi)))
40
+ val_dy = func(xs, ys + yeps)
41
+ return (val, (val_dx - val) / xeps, (val_dy - val) / yeps)
42
+
43
+
44
+ class FixedAxisArtistHelper(_FixedAxisArtistHelperBase):
45
+ """
46
+ Helper class for a fixed axis.
47
+ """
48
+
49
+ def __init__(self, grid_helper, side, nth_coord_ticks=None):
50
+ """
51
+ nth_coord = along which coordinate value varies.
52
+ nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
53
+ """
54
+
55
+ super().__init__(loc=side)
56
+
57
+ self.grid_helper = grid_helper
58
+ if nth_coord_ticks is None:
59
+ nth_coord_ticks = self.nth_coord
60
+ self.nth_coord_ticks = nth_coord_ticks
61
+
62
+ self.side = side
63
+
64
+ def update_lim(self, axes):
65
+ self.grid_helper.update_lim(axes)
66
+
67
+ def get_tick_transform(self, axes):
68
+ return axes.transData
69
+
70
+ def get_tick_iterators(self, axes):
71
+ """tick_loc, tick_angle, tick_label"""
72
+ v1, v2 = axes.get_ylim() if self.nth_coord == 0 else axes.get_xlim()
73
+ if v1 > v2: # Inverted limits.
74
+ side = {"left": "right", "right": "left",
75
+ "top": "bottom", "bottom": "top"}[self.side]
76
+ else:
77
+ side = self.side
78
+
79
+ angle_tangent = dict(left=90, right=90, bottom=0, top=0)[side]
80
+
81
+ def iter_major():
82
+ for nth_coord, show_labels in [
83
+ (self.nth_coord_ticks, True), (1 - self.nth_coord_ticks, False)]:
84
+ gi = self.grid_helper._grid_info[["lon", "lat"][nth_coord]]
85
+ for tick in gi["ticks"][side]:
86
+ yield (*tick["loc"], angle_tangent,
87
+ (tick["label"] if show_labels else ""))
88
+
89
+ return iter_major(), iter([])
90
+
91
+
92
+ class FloatingAxisArtistHelper(_FloatingAxisArtistHelperBase):
93
+
94
+ def __init__(self, grid_helper, nth_coord, value, axis_direction=None):
95
+ """
96
+ nth_coord = along which coordinate value varies.
97
+ nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
98
+ """
99
+ super().__init__(nth_coord, value)
100
+ self.value = value
101
+ self.grid_helper = grid_helper
102
+ self._extremes = -np.inf, np.inf
103
+ self._line_num_points = 100 # number of points to create a line
104
+
105
+ def set_extremes(self, e1, e2):
106
+ if e1 is None:
107
+ e1 = -np.inf
108
+ if e2 is None:
109
+ e2 = np.inf
110
+ self._extremes = e1, e2
111
+
112
+ def update_lim(self, axes):
113
+ self.grid_helper.update_lim(axes)
114
+
115
+ x1, x2 = axes.get_xlim()
116
+ y1, y2 = axes.get_ylim()
117
+ grid_finder = self.grid_helper.grid_finder
118
+ extremes = grid_finder.extreme_finder(grid_finder.inv_transform_xy,
119
+ x1, y1, x2, y2)
120
+
121
+ lon_min, lon_max, lat_min, lat_max = extremes
122
+ e_min, e_max = self._extremes # ranges of other coordinates
123
+ if self.nth_coord == 0:
124
+ lat_min = max(e_min, lat_min)
125
+ lat_max = min(e_max, lat_max)
126
+ elif self.nth_coord == 1:
127
+ lon_min = max(e_min, lon_min)
128
+ lon_max = min(e_max, lon_max)
129
+
130
+ lon_levs, lon_n, lon_factor = \
131
+ grid_finder.grid_locator1(lon_min, lon_max)
132
+ lat_levs, lat_n, lat_factor = \
133
+ grid_finder.grid_locator2(lat_min, lat_max)
134
+
135
+ if self.nth_coord == 0:
136
+ xx0 = np.full(self._line_num_points, self.value)
137
+ yy0 = np.linspace(lat_min, lat_max, self._line_num_points)
138
+ xx, yy = grid_finder.transform_xy(xx0, yy0)
139
+ elif self.nth_coord == 1:
140
+ xx0 = np.linspace(lon_min, lon_max, self._line_num_points)
141
+ yy0 = np.full(self._line_num_points, self.value)
142
+ xx, yy = grid_finder.transform_xy(xx0, yy0)
143
+
144
+ self._grid_info = {
145
+ "extremes": (lon_min, lon_max, lat_min, lat_max),
146
+ "lon_info": (lon_levs, lon_n, np.asarray(lon_factor)),
147
+ "lat_info": (lat_levs, lat_n, np.asarray(lat_factor)),
148
+ "lon_labels": grid_finder._format_ticks(
149
+ 1, "bottom", lon_factor, lon_levs),
150
+ "lat_labels": grid_finder._format_ticks(
151
+ 2, "bottom", lat_factor, lat_levs),
152
+ "line_xy": (xx, yy),
153
+ }
154
+
155
+ def get_axislabel_transform(self, axes):
156
+ return Affine2D() # axes.transData
157
+
158
+ def get_axislabel_pos_angle(self, axes):
159
+ def trf_xy(x, y):
160
+ trf = self.grid_helper.grid_finder.get_transform() + axes.transData
161
+ return trf.transform([x, y]).T
162
+
163
+ xmin, xmax, ymin, ymax = self._grid_info["extremes"]
164
+ if self.nth_coord == 0:
165
+ xx0 = self.value
166
+ yy0 = (ymin + ymax) / 2
167
+ elif self.nth_coord == 1:
168
+ xx0 = (xmin + xmax) / 2
169
+ yy0 = self.value
170
+ xy1, dxy1_dx, dxy1_dy = _value_and_jacobian(
171
+ trf_xy, xx0, yy0, (xmin, xmax), (ymin, ymax))
172
+ p = axes.transAxes.inverted().transform(xy1)
173
+ if 0 <= p[0] <= 1 and 0 <= p[1] <= 1:
174
+ d = [dxy1_dy, dxy1_dx][self.nth_coord]
175
+ return xy1, np.rad2deg(np.arctan2(*d[::-1]))
176
+ else:
177
+ return None, None
178
+
179
+ def get_tick_transform(self, axes):
180
+ return IdentityTransform() # axes.transData
181
+
182
+ def get_tick_iterators(self, axes):
183
+ """tick_loc, tick_angle, tick_label, (optionally) tick_label"""
184
+
185
+ lat_levs, lat_n, lat_factor = self._grid_info["lat_info"]
186
+ yy0 = lat_levs / lat_factor
187
+
188
+ lon_levs, lon_n, lon_factor = self._grid_info["lon_info"]
189
+ xx0 = lon_levs / lon_factor
190
+
191
+ e0, e1 = self._extremes
192
+
193
+ def trf_xy(x, y):
194
+ trf = self.grid_helper.grid_finder.get_transform() + axes.transData
195
+ return trf.transform(np.column_stack(np.broadcast_arrays(x, y))).T
196
+
197
+ # find angles
198
+ if self.nth_coord == 0:
199
+ mask = (e0 <= yy0) & (yy0 <= e1)
200
+ (xx1, yy1), (dxx1, dyy1), (dxx2, dyy2) = _value_and_jacobian(
201
+ trf_xy, self.value, yy0[mask], (-np.inf, np.inf), (e0, e1))
202
+ labels = self._grid_info["lat_labels"]
203
+
204
+ elif self.nth_coord == 1:
205
+ mask = (e0 <= xx0) & (xx0 <= e1)
206
+ (xx1, yy1), (dxx2, dyy2), (dxx1, dyy1) = _value_and_jacobian(
207
+ trf_xy, xx0[mask], self.value, (-np.inf, np.inf), (e0, e1))
208
+ labels = self._grid_info["lon_labels"]
209
+
210
+ labels = [l for l, m in zip(labels, mask) if m]
211
+
212
+ angle_normal = np.arctan2(dyy1, dxx1)
213
+ angle_tangent = np.arctan2(dyy2, dxx2)
214
+ mm = (dyy1 == 0) & (dxx1 == 0) # points with degenerate normal
215
+ angle_normal[mm] = angle_tangent[mm] + np.pi / 2
216
+
217
+ tick_to_axes = self.get_tick_transform(axes) - axes.transAxes
218
+ in_01 = functools.partial(
219
+ mpl.transforms._interval_contains_close, (0, 1))
220
+
221
+ def iter_major():
222
+ for x, y, normal, tangent, lab \
223
+ in zip(xx1, yy1, angle_normal, angle_tangent, labels):
224
+ c2 = tick_to_axes.transform((x, y))
225
+ if in_01(c2[0]) and in_01(c2[1]):
226
+ yield [x, y], *np.rad2deg([normal, tangent]), lab
227
+
228
+ return iter_major(), iter([])
229
+
230
+ def get_line_transform(self, axes):
231
+ return axes.transData
232
+
233
+ def get_line(self, axes):
234
+ self.update_lim(axes)
235
+ x, y = self._grid_info["line_xy"]
236
+ return Path(np.column_stack([x, y]))
237
+
238
+
239
+ class GridHelperCurveLinear(GridHelperBase):
240
+ def __init__(self, aux_trans,
241
+ extreme_finder=None,
242
+ grid_locator1=None,
243
+ grid_locator2=None,
244
+ tick_formatter1=None,
245
+ tick_formatter2=None):
246
+ """
247
+ Parameters
248
+ ----------
249
+ aux_trans : `.Transform` or tuple[Callable, Callable]
250
+ The transform from curved coordinates to rectilinear coordinate:
251
+ either a `.Transform` instance (which provides also its inverse),
252
+ or a pair of callables ``(trans, inv_trans)`` that define the
253
+ transform and its inverse. The callables should have signature::
254
+
255
+ x_rect, y_rect = trans(x_curved, y_curved)
256
+ x_curved, y_curved = inv_trans(x_rect, y_rect)
257
+
258
+ extreme_finder
259
+
260
+ grid_locator1, grid_locator2
261
+ Grid locators for each axis.
262
+
263
+ tick_formatter1, tick_formatter2
264
+ Tick formatters for each axis.
265
+ """
266
+ super().__init__()
267
+ self._grid_info = None
268
+ self.grid_finder = GridFinder(aux_trans,
269
+ extreme_finder,
270
+ grid_locator1,
271
+ grid_locator2,
272
+ tick_formatter1,
273
+ tick_formatter2)
274
+
275
+ def update_grid_finder(self, aux_trans=None, **kwargs):
276
+ if aux_trans is not None:
277
+ self.grid_finder.update_transform(aux_trans)
278
+ self.grid_finder.update(**kwargs)
279
+ self._old_limits = None # Force revalidation.
280
+
281
+ @_api.make_keyword_only("3.9", "nth_coord")
282
+ def new_fixed_axis(
283
+ self, loc, nth_coord=None, axis_direction=None, offset=None, axes=None):
284
+ if axes is None:
285
+ axes = self.axes
286
+ if axis_direction is None:
287
+ axis_direction = loc
288
+ helper = FixedAxisArtistHelper(self, loc, nth_coord_ticks=nth_coord)
289
+ axisline = AxisArtist(axes, helper, axis_direction=axis_direction)
290
+ # Why is clip not set on axisline, unlike in new_floating_axis or in
291
+ # the floating_axig.GridHelperCurveLinear subclass?
292
+ return axisline
293
+
294
+ def new_floating_axis(self, nth_coord, value, axes=None, axis_direction="bottom"):
295
+ if axes is None:
296
+ axes = self.axes
297
+ helper = FloatingAxisArtistHelper(
298
+ self, nth_coord, value, axis_direction)
299
+ axisline = AxisArtist(axes, helper)
300
+ axisline.line.set_clip_on(True)
301
+ axisline.line.set_clip_box(axisline.axes.bbox)
302
+ # axisline.major_ticklabels.set_visible(True)
303
+ # axisline.minor_ticklabels.set_visible(False)
304
+ return axisline
305
+
306
+ def _update_grid(self, x1, y1, x2, y2):
307
+ self._grid_info = self.grid_finder.get_grid_info(x1, y1, x2, y2)
308
+
309
+ def get_gridlines(self, which="major", axis="both"):
310
+ grid_lines = []
311
+ if axis in ["both", "x"]:
312
+ for gl in self._grid_info["lon"]["lines"]:
313
+ grid_lines.extend(gl)
314
+ if axis in ["both", "y"]:
315
+ for gl in self._grid_info["lat"]["lines"]:
316
+ grid_lines.extend(gl)
317
+ return grid_lines
318
+
319
+ @_api.deprecated("3.9")
320
+ def get_tick_iterator(self, nth_coord, axis_side, minor=False):
321
+ angle_tangent = dict(left=90, right=90, bottom=0, top=0)[axis_side]
322
+ lon_or_lat = ["lon", "lat"][nth_coord]
323
+ if not minor: # major ticks
324
+ for tick in self._grid_info[lon_or_lat]["ticks"][axis_side]:
325
+ yield *tick["loc"], angle_tangent, tick["label"]
326
+ else:
327
+ for tick in self._grid_info[lon_or_lat]["ticks"][axis_side]:
328
+ yield *tick["loc"], angle_tangent, ""
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/parasite_axes.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from mpl_toolkits.axes_grid1.parasite_axes import (
2
+ host_axes_class_factory, parasite_axes_class_factory)
3
+ from .axislines import Axes
4
+
5
+
6
+ ParasiteAxes = parasite_axes_class_factory(Axes)
7
+ HostAxes = SubplotHost = host_axes_class_factory(Axes)
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/__init__.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+
4
+ # Check that the test directories exist
5
+ if not (Path(__file__).parent / "baseline_images").exists():
6
+ raise OSError(
7
+ 'The baseline image directory does not exist. '
8
+ 'This is most likely because the test data is not installed. '
9
+ 'You may need to install matplotlib from source to get the '
10
+ 'test data.')
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/test_axis_artist.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ from matplotlib.testing.decorators import image_comparison
3
+
4
+ from mpl_toolkits.axisartist import AxisArtistHelperRectlinear
5
+ from mpl_toolkits.axisartist.axis_artist import (AxisArtist, AxisLabel,
6
+ LabelBase, Ticks, TickLabels)
7
+
8
+
9
+ @image_comparison(['axis_artist_ticks.png'], style='default')
10
+ def test_ticks():
11
+ fig, ax = plt.subplots()
12
+
13
+ ax.xaxis.set_visible(False)
14
+ ax.yaxis.set_visible(False)
15
+
16
+ locs_angles = [((i / 10, 0.0), i * 30) for i in range(-1, 12)]
17
+
18
+ ticks_in = Ticks(ticksize=10, axis=ax.xaxis)
19
+ ticks_in.set_locs_angles(locs_angles)
20
+ ax.add_artist(ticks_in)
21
+
22
+ ticks_out = Ticks(ticksize=10, tick_out=True, color='C3', axis=ax.xaxis)
23
+ ticks_out.set_locs_angles(locs_angles)
24
+ ax.add_artist(ticks_out)
25
+
26
+
27
+ @image_comparison(['axis_artist_labelbase.png'], style='default')
28
+ def test_labelbase():
29
+ # Remove this line when this test image is regenerated.
30
+ plt.rcParams['text.kerning_factor'] = 6
31
+
32
+ fig, ax = plt.subplots()
33
+
34
+ ax.plot([0.5], [0.5], "o")
35
+
36
+ label = LabelBase(0.5, 0.5, "Test")
37
+ label._ref_angle = -90
38
+ label._offset_radius = 50
39
+ label.set_rotation(-90)
40
+ label.set(ha="center", va="top")
41
+ ax.add_artist(label)
42
+
43
+
44
+ @image_comparison(['axis_artist_ticklabels.png'], style='default')
45
+ def test_ticklabels():
46
+ # Remove this line when this test image is regenerated.
47
+ plt.rcParams['text.kerning_factor'] = 6
48
+
49
+ fig, ax = plt.subplots()
50
+
51
+ ax.xaxis.set_visible(False)
52
+ ax.yaxis.set_visible(False)
53
+
54
+ ax.plot([0.2, 0.4], [0.5, 0.5], "o")
55
+
56
+ ticks = Ticks(ticksize=10, axis=ax.xaxis)
57
+ ax.add_artist(ticks)
58
+ locs_angles_labels = [((0.2, 0.5), -90, "0.2"),
59
+ ((0.4, 0.5), -120, "0.4")]
60
+ tick_locs_angles = [(xy, a + 180) for xy, a, l in locs_angles_labels]
61
+ ticks.set_locs_angles(tick_locs_angles)
62
+
63
+ ticklabels = TickLabels(axis_direction="left")
64
+ ticklabels._locs_angles_labels = locs_angles_labels
65
+ ticklabels.set_pad(10)
66
+ ax.add_artist(ticklabels)
67
+
68
+ ax.plot([0.5], [0.5], "s")
69
+ axislabel = AxisLabel(0.5, 0.5, "Test")
70
+ axislabel._offset_radius = 20
71
+ axislabel._ref_angle = 0
72
+ axislabel.set_axis_direction("bottom")
73
+ ax.add_artist(axislabel)
74
+
75
+ ax.set_xlim(0, 1)
76
+ ax.set_ylim(0, 1)
77
+
78
+
79
+ @image_comparison(['axis_artist.png'], style='default')
80
+ def test_axis_artist():
81
+ # Remove this line when this test image is regenerated.
82
+ plt.rcParams['text.kerning_factor'] = 6
83
+
84
+ fig, ax = plt.subplots()
85
+
86
+ ax.xaxis.set_visible(False)
87
+ ax.yaxis.set_visible(False)
88
+
89
+ for loc in ('left', 'right', 'bottom'):
90
+ helper = AxisArtistHelperRectlinear.Fixed(ax, loc=loc)
91
+ axisline = AxisArtist(ax, helper, offset=None, axis_direction=loc)
92
+ ax.add_artist(axisline)
93
+
94
+ # Settings for bottom AxisArtist.
95
+ axisline.set_label("TTT")
96
+ axisline.major_ticks.set_tick_out(False)
97
+ axisline.label.set_pad(5)
98
+
99
+ ax.set_ylabel("Test")
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/test_axislines.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ from matplotlib.testing.decorators import image_comparison
4
+ from matplotlib.transforms import IdentityTransform
5
+
6
+ from mpl_toolkits.axisartist.axislines import AxesZero, SubplotZero, Subplot
7
+ from mpl_toolkits.axisartist import Axes, SubplotHost
8
+
9
+
10
+ @image_comparison(['SubplotZero.png'], style='default')
11
+ def test_SubplotZero():
12
+ # Remove this line when this test image is regenerated.
13
+ plt.rcParams['text.kerning_factor'] = 6
14
+
15
+ fig = plt.figure()
16
+
17
+ ax = SubplotZero(fig, 1, 1, 1)
18
+ fig.add_subplot(ax)
19
+
20
+ ax.axis["xzero"].set_visible(True)
21
+ ax.axis["xzero"].label.set_text("Axis Zero")
22
+
23
+ for n in ["top", "right"]:
24
+ ax.axis[n].set_visible(False)
25
+
26
+ xx = np.arange(0, 2 * np.pi, 0.01)
27
+ ax.plot(xx, np.sin(xx))
28
+ ax.set_ylabel("Test")
29
+
30
+
31
+ @image_comparison(['Subplot.png'], style='default')
32
+ def test_Subplot():
33
+ # Remove this line when this test image is regenerated.
34
+ plt.rcParams['text.kerning_factor'] = 6
35
+
36
+ fig = plt.figure()
37
+
38
+ ax = Subplot(fig, 1, 1, 1)
39
+ fig.add_subplot(ax)
40
+
41
+ xx = np.arange(0, 2 * np.pi, 0.01)
42
+ ax.plot(xx, np.sin(xx))
43
+ ax.set_ylabel("Test")
44
+
45
+ ax.axis["top"].major_ticks.set_tick_out(True)
46
+ ax.axis["bottom"].major_ticks.set_tick_out(True)
47
+
48
+ ax.axis["bottom"].set_label("Tk0")
49
+
50
+
51
+ def test_Axes():
52
+ fig = plt.figure()
53
+ ax = Axes(fig, [0.15, 0.1, 0.65, 0.8])
54
+ fig.add_axes(ax)
55
+ ax.plot([1, 2, 3], [0, 1, 2])
56
+ ax.set_xscale('log')
57
+ fig.canvas.draw()
58
+
59
+
60
+ @image_comparison(['ParasiteAxesAuxTrans_meshplot.png'],
61
+ remove_text=True, style='default', tol=0.075)
62
+ def test_ParasiteAxesAuxTrans():
63
+ data = np.ones((6, 6))
64
+ data[2, 2] = 2
65
+ data[0, :] = 0
66
+ data[-2, :] = 0
67
+ data[:, 0] = 0
68
+ data[:, -2] = 0
69
+ x = np.arange(6)
70
+ y = np.arange(6)
71
+ xx, yy = np.meshgrid(x, y)
72
+
73
+ funcnames = ['pcolor', 'pcolormesh', 'contourf']
74
+
75
+ fig = plt.figure()
76
+ for i, name in enumerate(funcnames):
77
+
78
+ ax1 = SubplotHost(fig, 1, 3, i+1)
79
+ fig.add_subplot(ax1)
80
+
81
+ ax2 = ax1.get_aux_axes(IdentityTransform(), viewlim_mode=None)
82
+ if name.startswith('pcolor'):
83
+ getattr(ax2, name)(xx, yy, data[:-1, :-1])
84
+ else:
85
+ getattr(ax2, name)(xx, yy, data)
86
+ ax1.set_xlim((0, 5))
87
+ ax1.set_ylim((0, 5))
88
+
89
+ ax2.contour(xx, yy, data, colors='k')
90
+
91
+
92
+ @image_comparison(['axisline_style.png'], remove_text=True, style='mpl20')
93
+ def test_axisline_style():
94
+ fig = plt.figure(figsize=(2, 2))
95
+ ax = fig.add_subplot(axes_class=AxesZero)
96
+ ax.axis["xzero"].set_axisline_style("-|>")
97
+ ax.axis["xzero"].set_visible(True)
98
+ ax.axis["yzero"].set_axisline_style("->")
99
+ ax.axis["yzero"].set_visible(True)
100
+
101
+ for direction in ("left", "right", "bottom", "top"):
102
+ ax.axis[direction].set_visible(False)
103
+
104
+
105
+ @image_comparison(['axisline_style_size_color.png'], remove_text=True,
106
+ style='mpl20')
107
+ def test_axisline_style_size_color():
108
+ fig = plt.figure(figsize=(2, 2))
109
+ ax = fig.add_subplot(axes_class=AxesZero)
110
+ ax.axis["xzero"].set_axisline_style("-|>", size=2.0, facecolor='r')
111
+ ax.axis["xzero"].set_visible(True)
112
+ ax.axis["yzero"].set_axisline_style("->, size=1.5")
113
+ ax.axis["yzero"].set_visible(True)
114
+
115
+ for direction in ("left", "right", "bottom", "top"):
116
+ ax.axis[direction].set_visible(False)
117
+
118
+
119
+ @image_comparison(['axisline_style_tight.png'], remove_text=True,
120
+ style='mpl20')
121
+ def test_axisline_style_tight():
122
+ fig = plt.figure(figsize=(2, 2))
123
+ ax = fig.add_subplot(axes_class=AxesZero)
124
+ ax.axis["xzero"].set_axisline_style("-|>", size=5, facecolor='g')
125
+ ax.axis["xzero"].set_visible(True)
126
+ ax.axis["yzero"].set_axisline_style("->, size=8")
127
+ ax.axis["yzero"].set_visible(True)
128
+
129
+ for direction in ("left", "right", "bottom", "top"):
130
+ ax.axis[direction].set_visible(False)
131
+
132
+ fig.tight_layout()
133
+
134
+
135
+ @image_comparison(['subplotzero_ylabel.png'], style='mpl20')
136
+ def test_subplotzero_ylabel():
137
+ fig = plt.figure()
138
+ ax = fig.add_subplot(111, axes_class=SubplotZero)
139
+
140
+ ax.set(xlim=(-3, 7), ylim=(-3, 7), xlabel="x", ylabel="y")
141
+
142
+ zero_axis = ax.axis["xzero", "yzero"]
143
+ zero_axis.set_visible(True) # they are hidden by default
144
+
145
+ ax.axis["left", "right", "bottom", "top"].set_visible(False)
146
+
147
+ zero_axis.set_axisline_style("->")
vlmpy310/lib/python3.10/site-packages/mpl_toolkits/axisartist/tests/test_grid_finder.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from matplotlib.transforms import Bbox
5
+ from mpl_toolkits.axisartist.grid_finder import (
6
+ _find_line_box_crossings, FormatterPrettyPrint, MaxNLocator)
7
+
8
+
9
+ def test_find_line_box_crossings():
10
+ x = np.array([-3, -2, -1, 0., 1, 2, 3, 2, 1, 0, -1, -2, -3, 5])
11
+ y = np.arange(len(x))
12
+ bbox = Bbox.from_extents(-2, 3, 2, 12.5)
13
+ left, right, bottom, top = _find_line_box_crossings(
14
+ np.column_stack([x, y]), bbox)
15
+ ((lx0, ly0), la0), ((lx1, ly1), la1), = left
16
+ ((rx0, ry0), ra0), ((rx1, ry1), ra1), = right
17
+ ((bx0, by0), ba0), = bottom
18
+ ((tx0, ty0), ta0), = top
19
+ assert (lx0, ly0, la0) == (-2, 11, 135)
20
+ assert (lx1, ly1, la1) == pytest.approx((-2., 12.125, 7.125016))
21
+ assert (rx0, ry0, ra0) == (2, 5, 45)
22
+ assert (rx1, ry1, ra1) == (2, 7, 135)
23
+ assert (bx0, by0, ba0) == (0, 3, 45)
24
+ assert (tx0, ty0, ta0) == pytest.approx((1., 12.5, 7.125016))
25
+
26
+
27
+ def test_pretty_print_format():
28
+ locator = MaxNLocator()
29
+ locs, nloc, factor = locator(0, 100)
30
+
31
+ fmt = FormatterPrettyPrint()
32
+
33
+ assert fmt("left", None, locs) == \
34
+ [r'$\mathdefault{%d}$' % (l, ) for l in locs]
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (877 Bytes). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/_locale_data.cpython-310.pyc ADDED
Binary file (3.2 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/auth.cpython-310.pyc ADDED
Binary file (41.9 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/autoreload.cpython-310.pyc ADDED
Binary file (7.84 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/concurrent.cpython-310.pyc ADDED
Binary file (8.19 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/curl_httpclient.cpython-310.pyc ADDED
Binary file (14 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/escape.cpython-310.pyc ADDED
Binary file (11.6 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/gen.cpython-310.pyc ADDED
Binary file (26.5 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/http1connection.cpython-310.pyc ADDED
Binary file (23.7 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/httpclient.cpython-310.pyc ADDED
Binary file (28.7 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/httpserver.cpython-310.pyc ADDED
Binary file (14.2 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/httputil.cpython-310.pyc ADDED
Binary file (32.1 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/ioloop.cpython-310.pyc ADDED
Binary file (32.4 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/iostream.cpython-310.pyc ADDED
Binary file (44.4 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/locale.cpython-310.pyc ADDED
Binary file (16.5 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/locks.cpython-310.pyc ADDED
Binary file (18.4 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/log.cpython-310.pyc ADDED
Binary file (8.48 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/netutil.cpython-310.pyc ADDED
Binary file (19 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/options.cpython-310.pyc ADDED
Binary file (23.8 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/process.cpython-310.pyc ADDED
Binary file (10.2 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/queues.cpython-310.pyc ADDED
Binary file (13.4 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/routing.cpython-310.pyc ADDED
Binary file (24.3 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/simple_httpclient.cpython-310.pyc ADDED
Binary file (18.7 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/tcpclient.cpython-310.pyc ADDED
Binary file (9.19 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/tcpserver.cpython-310.pyc ADDED
Binary file (12.4 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/template.cpython-310.pyc ADDED
Binary file (34 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/testing.cpython-310.pyc ADDED
Binary file (28.1 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/util.cpython-310.pyc ADDED
Binary file (14.2 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/websocket.cpython-310.pyc ADDED
Binary file (51.5 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/__pycache__/wsgi.cpython-310.pyc ADDED
Binary file (9.15 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (166 Bytes). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/asyncio_test.cpython-310.pyc ADDED
Binary file (9.39 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/autoreload_test.cpython-310.pyc ADDED
Binary file (5.7 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/concurrent_test.cpython-310.pyc ADDED
Binary file (8.2 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/escape_test.cpython-310.pyc ADDED
Binary file (9.73 kB). View file
 
vlmpy310/lib/python3.10/site-packages/tornado/test/__pycache__/gen_test.cpython-310.pyc ADDED
Binary file (37.7 kB). View file