ExternalAxesContainer#
- class ExternalAxesContainer(*args, external_axes_class=None, external_axes_kwargs=None, **kwargs)[source]#
Bases:
CartesianAxesContainer axes that wraps an external axes instance.
This class inherits from ultraplot’s CartesianAxes and creates/manages an external axes as a child. It provides ultraplot’s interface while delegating drawing and interaction to the wrapped external axes.
- Parameters:
*args – Positional arguments passed to Axes.__init__
external_axes_class (
type) – The external axes class to instantiate (e.g., mpltern.TernaryAxes)external_axes_kwargs (
dict, optional) – Keyword arguments to pass to the external axes constructorexternal_shrink_factor (
float, optional, default:rc['external.shrink']=0.9) – The factor by which to shrink the external axes within the container to leave room for labels. For ternary plots, labels extend significantly beyond the plot area, so a value of 0.90 (10% padding) helps prevent overlap with adjacent subplots while keeping the axes large.external_padding (
float, optional, default:5.0) – Padding in points to add around the external axes tight bbox. This creates space between the external axes and adjacent subplots, preventing overlap with tick labels or other elements. Set to 0 to disable padding.**kwargs – Keyword arguments passed to Axes.__init__
Notes
When using external axes containers with multiple subplots, the external axes (e.g., ternary plots) are automatically shrunk to prevent label overlap with adjacent subplots. If you still experience overlap, you can:
Increase spacing with
wspaceorhspacein subplots()Decrease
external_shrink_factor(more aggressive shrinking)Use tight_layout or constrained_layout for automatic spacing
Example:
uplt.subplots(ncols=2, projection=('ternary', None), wspace=5)To reduce padding between external axes and adjacent subplots, use:
external_padding=2orexternal_padding=0to disable padding entirely.Initialize the container and create the external axes child.
Methods Summary
clear()Clear the container and mark external axes as stale.
contour(*args, **kwargs)Delegate contour to external axes.
contourf(*args, **kwargs)Delegate contourf to external axes.
draw(renderer)Override draw to render container (with abc/titles) and external axes.
fill(*args, **kwargs)Delegate fill to external axes.
format(**kwargs)Format the container and delegate to external axes where appropriate.
Get the wrapped external axes instance.
Get the external axes child (alias for get_external_axes).
get_tightbbox(renderer, *args, **kwargs)Override to return the container bbox for consistent layout positioning.
Check if this container has an external axes child.
hexbin(*args, **kwargs)Delegate hexbin to external axes.
imshow(*args, **kwargs)Delegate imshow to external axes.
pcolormesh(*args, **kwargs)Delegate pcolormesh to external axes.
plot(*args, **kwargs)Delegate plot to external axes.
scatter(*args, **kwargs)Delegate scatter to external axes.
set(*[, adjustable, agg_filter, alpha, ...])Set multiple properties at once.
set_position(pos[, which])Override to sync position changes to external axes.
stale_callback(*args, **kwargs)Mark external axes as stale when container is marked stale.
tricontour(*args, **kwargs)Delegate tricontour to external axes.
tricontourf(*args, **kwargs)Delegate tricontourf to external axes.
tripcolor(*args, **kwargs)Delegate tripcolor to external axes.
triplot(*args, **kwargs)Delegate triplot to external axes.
Methods Documentation
- format(**kwargs)[source]#
Format the container and delegate to external axes where appropriate.
This method handles ultraplot-specific formatting on the container and attempts to delegate common parameters to the external axes.
- Parameters:
**kwargs – Formatting parameters. Common matplotlib parameters (title, xlabel, ylabel, xlim, ylim) are delegated to the external axes if supported.
- get_external_axes()[source]#
Get the wrapped external axes instance.
- Returns:
axes– The external axes instance, or None if not created
- get_external_child()[source]#
Get the external axes child (alias for get_external_axes).
- Returns:
axes– The external axes instance, or None if not created
- get_tightbbox(renderer, *args, **kwargs)[source]#
Override to return the container bbox for consistent layout positioning.
By returning the container’s bbox, we ensure the layout engine positions the container properly within the subplot grid, and we rely on our iterative shrinking to ensure the external axes fits within the container.
- has_external_child()[source]#
Check if this container has an external axes child.
- Returns:
bool– True if an external axes instance exists, False otherwise
- set(*, adjustable=<UNSET>, agg_filter=<UNSET>, alpha=<UNSET>, anchor=<UNSET>, animated=<UNSET>, aspect=<UNSET>, autoscale_on=<UNSET>, autoscalex_on=<UNSET>, autoscaley_on=<UNSET>, axes_locator=<UNSET>, axisbelow=<UNSET>, box_aspect=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, external=<UNSET>, facecolor=<UNSET>, forward_navigation_events=<UNSET>, frame_on=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, navigate=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, prop_cycle=<UNSET>, rasterization_zorder=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, subplotspec=<UNSET>, title=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, xbound=<UNSET>, xlabel=<UNSET>, xlim=<UNSET>, xmargin=<UNSET>, xscale=<UNSET>, xticklabels=<UNSET>, xticks=<UNSET>, ybound=<UNSET>, ylabel=<UNSET>, ylim=<UNSET>, ymargin=<UNSET>, yscale=<UNSET>, yticklabels=<UNSET>, yticks=<UNSET>, zorder=<UNSET>)#
Set multiple properties at once.
Supported properties are
Property
Description
{‘box’, ‘datalim’}
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
float or None
(float, float) or {‘C’, ‘SW’, ‘S’, ‘SE’, ‘E’, ‘NE’, …}
bool
{‘auto’, ‘equal’} or float
bool
unknown
unknown
Callable[[Axes, Renderer], Bbox]
bool or ‘line’
float or None
BboxBaseor Nonebool
Patch or (Path, Transform) or None
externalunknown
bool or “auto”
bool
str
bool
object
bool
bool
unknown
list of
AbstractPathEffectNone or bool or float or callable
positionunknown
float or None
bool
(scale: float, length: float, randomness: float)
bool or None
unknown
str
str
bool
(lower: float, upper: float)
str
(left: float, right: float)
float greater than -0.5
str or
ScaleBaseunknown
unknown
(lower: float, upper: float)
str
(bottom: float, top: float)
float greater than -0.5
str or
ScaleBaseunknown
unknown
float