|
5 | 5 |
|
6 | 6 | import animatplot as amp |
7 | 7 |
|
8 | | -from .utils import _decompose_regions, _is_core_only, plot_separatrices, plot_targets |
| 8 | +from .utils import ( |
| 9 | + _create_norm, |
| 10 | + _decompose_regions, |
| 11 | + _is_core_only, |
| 12 | + plot_separatrices, |
| 13 | + plot_targets, |
| 14 | +) |
9 | 15 | from matplotlib.animation import PillowWriter |
10 | 16 |
|
11 | 17 |
|
@@ -80,6 +86,7 @@ def animate_poloidal( |
80 | 86 | axis_coords=None, |
81 | 87 | vmin=None, |
82 | 88 | vmax=None, |
| 89 | + logscale=False, |
83 | 90 | animate=True, |
84 | 91 | save_as=None, |
85 | 92 | fps=10, |
@@ -125,6 +132,12 @@ def animate_poloidal( |
125 | 132 | Minimum value for the color scale |
126 | 133 | vmax : float, optional |
127 | 134 | Maximum value for the color scale |
| 135 | + logscale : bool or float, optional |
| 136 | + If True, default to a logarithmic color scale instead of a linear one. |
| 137 | + If a non-bool type is passed it is treated as a float used to set the linear |
| 138 | + threshold of a symmetric logarithmic scale as |
| 139 | + linthresh=min(abs(vmin),abs(vmax))*logscale, defaults to 1e-5 if True is |
| 140 | + passed. |
128 | 141 | animate : bool, optional |
129 | 142 | If set to false, do not create the animation, just return the blocks |
130 | 143 | save_as : True or str, optional |
@@ -188,11 +201,7 @@ def animate_poloidal( |
188 | 201 | extend = "neither" |
189 | 202 |
|
190 | 203 | # create colorbar |
191 | | - norm = ( |
192 | | - kwargs["norm"] |
193 | | - if "norm" in kwargs |
194 | | - else matplotlib.colors.Normalize(vmin=vmin, vmax=vmax) |
195 | | - ) |
| 204 | + norm = _create_norm(logscale, kwargs.get("norm", None), vmin, vmax) |
196 | 205 | sm = plt.cm.ScalarMappable(norm=norm, cmap=cmap) |
197 | 206 | sm.set_array([]) |
198 | 207 | cmap = sm.get_cmap() |
@@ -279,6 +288,7 @@ def animate_pcolormesh( |
279 | 288 | vmin=None, |
280 | 289 | vmax=None, |
281 | 290 | vsymmetric=False, |
| 291 | + logscale=False, |
282 | 292 | fps=10, |
283 | 293 | save_as=None, |
284 | 294 | ax=None, |
@@ -325,6 +335,12 @@ def animate_pcolormesh( |
325 | 335 | data across whole timeseries. |
326 | 336 | vsymmetric : bool, optional |
327 | 337 | If set to true, make the color-scale symmetric |
| 338 | + logscale : bool or float, optional |
| 339 | + If True, default to a logarithmic color scale instead of a linear one. |
| 340 | + If a non-bool type is passed it is treated as a float used to set the linear |
| 341 | + threshold of a symmetric logarithmic scale as |
| 342 | + linthresh=min(abs(vmin),abs(vmax))*logscale, defaults to 1e-5 if True is |
| 343 | + passed. |
328 | 344 | fps : int, optional |
329 | 345 | Frames per second of resulting gif |
330 | 346 | save_as : True or str, optional |
@@ -399,17 +415,15 @@ def animate_pcolormesh( |
399 | 415 | # well with dask arrays! |
400 | 416 | image_data = data.values |
401 | 417 |
|
402 | | - if "norm" not in kwargs: |
403 | | - # If not specified, determine max and min values across entire data series |
404 | | - if vmax is None: |
405 | | - vmax = np.max(image_data) |
406 | | - if vmin is None: |
407 | | - vmin = np.min(image_data) |
408 | | - if vsymmetric: |
409 | | - vmax = max(np.abs(vmin), np.abs(vmax)) |
410 | | - vmin = -vmax |
411 | | - kwargs["vmin"] = vmin |
412 | | - kwargs["vmax"] = vmax |
| 418 | + # If not specified, determine max and min values across entire data series |
| 419 | + if vmax is None: |
| 420 | + vmax = np.max(image_data) |
| 421 | + if vmin is None: |
| 422 | + vmin = np.min(image_data) |
| 423 | + if vsymmetric: |
| 424 | + vmax = max(np.abs(vmin), np.abs(vmax)) |
| 425 | + vmin = -vmax |
| 426 | + kwargs["norm"] = _create_norm(logscale, kwargs.get("norm", None), vmin, vmax) |
413 | 427 |
|
414 | 428 | if not ax: |
415 | 429 | fig, ax = plt.subplots() |
|
0 commit comments