23
23
import numpy as np
24
24
25
25
from ._util import colored_line
26
+ from ._vendor .matplotlib import _TransformedBoundsLocator
26
27
from ..calc import dewpoint , dry_lapse , el , lcl , moist_lapse , vapor_pressure
27
28
from ..calc .tools import _delete_masked_points
28
29
from ..interpolate import interpolate_1d
@@ -264,7 +265,7 @@ class SkewT:
264
265
265
266
"""
266
267
267
- def __init__ (self , fig = None , rotation = 30 , subplot = None , rect = None , aspect = 80.5 ):
268
+ def __init__ (self , fig = None , rotation = 30 , subplot = None , rect = None , aspect = 80.5 , ** kwargs ):
268
269
r"""Create SkewT - logP plots.
269
270
270
271
Parameters
@@ -289,6 +290,8 @@ def __init__(self, fig=None, rotation=30, subplot=None, rect=None, aspect=80.5):
289
290
Aspect ratio (i.e. ratio of y-scale to x-scale) to maintain in the plot.
290
291
Defaults to 80.5. Passing the string ``'auto'`` tells matplotlib to handle
291
292
the aspect ratio automatically (this is not recommended for SkewT).
293
+ kwargs
294
+ Additional keyword arguments passed when creating the axes.
292
295
293
296
"""
294
297
if fig is None :
@@ -301,7 +304,7 @@ def __init__(self, fig=None, rotation=30, subplot=None, rect=None, aspect=80.5):
301
304
raise ValueError ("Specify only one of `rect' and `subplot', but not both" )
302
305
303
306
elif rect :
304
- self .ax = fig .add_axes (rect , projection = 'skewx' , rotation = rotation )
307
+ self .ax = fig .add_axes (rect , projection = 'skewx' , rotation = rotation , ** kwargs )
305
308
306
309
else :
307
310
if subplot is not None :
@@ -313,7 +316,12 @@ def __init__(self, fig=None, rotation=30, subplot=None, rect=None, aspect=80.5):
313
316
else :
314
317
subplot = (1 , 1 , 1 )
315
318
316
- self .ax = fig .add_subplot (* subplot , projection = 'skewx' , rotation = rotation )
319
+ self .ax = fig .add_subplot (
320
+ * subplot ,
321
+ projection = 'skewx' ,
322
+ rotation = rotation ,
323
+ ** kwargs
324
+ )
317
325
318
326
# Set the yaxis as inverted with log scaling
319
327
self .ax .set_yscale ('log' )
@@ -342,6 +350,73 @@ def __init__(self, fig=None, rotation=30, subplot=None, rect=None, aspect=80.5):
342
350
if matplotlib .__version__ [:3 ] > '3.1' :
343
351
self .ax .set_aspect (aspect , adjustable = 'box' )
344
352
353
+ @classmethod
354
+ def inset (cls , ax , bounds , transform = None , zorder = 5 , rotation = 30 , aspect = 80.5 , ** kwargs ):
355
+ r"""Create SkewT - logP plot as an inset.
356
+
357
+ Parameters
358
+ ----------
359
+ ax : matplotlib.axes.Axes
360
+ Source axes on which to place the inset SkewT.
361
+ bounds : tuple[float, float, float, float]
362
+ Rectangle (left, bottom, width, height) in which to place the axes. This
363
+ allows the user to place the axes at an arbitrary point on the figure. See the
364
+ ``transform`` argument for controlling the coordinate system used in these bounds.
365
+ transform : matplotlib.transforms.Transform, optional
366
+ Defaults to ``ax.transData``, the coordinate system for the data. Other options
367
+ include ``ax.transAxes`` for axes-relative coordinates, ``fig.transFirgure`` for
368
+ figure-relative coordinates, or
369
+ ``ax.get_x_axis_transform()``/``ax.get_y_axis_transform()`` for blended
370
+ coordinates (data coordinates on one axis and axes coordinates on the other).
371
+ zorder : number, optional
372
+ Defaults to 5. Adjust higher or lower to change whether it is above or below data
373
+ plotted on the parent axes.
374
+ rotation : float or int, optional
375
+ Controls the rotation of temperature relative to horizontal. Given
376
+ in degrees counterclockwise from x-axis. Defaults to 30 degrees.
377
+ aspect : float, int, or 'auto', optional
378
+ Aspect ratio (i.e. ratio of y-scale to x-scale) to maintain in the plot.
379
+ Defaults to 80.5. Passing the string ``'auto'`` tells matplotlib to handle
380
+ the aspect ratio automatically (this is not recommended for SkewT).
381
+ kwargs
382
+ Additional keyword arguments passed when creating the axes.
383
+
384
+ Returns
385
+ -------
386
+ SkewT
387
+
388
+ """
389
+ if transform is None :
390
+ transform = ax .transData
391
+
392
+ # This segement copied with modification from matplotlib: Copyright (c) 2012-2013
393
+ # Matplotlib Development Team; All Rights Reserved. See license agreement in
394
+ # _vendor/matplotlib.py. Modified from original to have parent Axes be an argument
395
+ # rather than self, create a SkewT object rather than Axes directly, and use Axes from
396
+ # that SkewT instance instead of directly created Axes.
397
+
398
+ # This puts the rectangle into figure-relative coordinates.
399
+ inset_locator = _TransformedBoundsLocator (bounds , transform )
400
+ bounds = inset_locator (ax , None ).bounds
401
+
402
+ # Create the skewT using the transformed bounds
403
+ skew_t = cls (
404
+ ax .figure ,
405
+ rotation = rotation ,
406
+ rect = bounds ,
407
+ aspect = aspect ,
408
+ zorder = zorder ,
409
+ ** kwargs
410
+ )
411
+
412
+ # this locator lets the axes move if in data coordinates.
413
+ # it gets called in `ax.apply_aspect() (of all places)
414
+ skew_t .ax .set_axes_locator (inset_locator )
415
+
416
+ # End copy
417
+
418
+ return skew_t
419
+
345
420
def plot (self , pressure , t , * args , ** kwargs ):
346
421
r"""Plot data.
347
422
0 commit comments