pydrex.axes

PyDRex: Custom Matplotlib Axes subclasses.

  1"""> PyDRex: Custom Matplotlib Axes subclasses."""
  2
  3import matplotlib as mpl
  4import matplotlib.axes as mplax
  5import numpy as np
  6from matplotlib.projections import register_projection
  7
  8from pydrex import geometry as _geo
  9from pydrex import stats as _stats
 10
 11
 12class PoleFigureAxes(mplax.Axes):
 13    """Axes class designed for crystallographic pole figures.
 14
 15    Thin `matplotlib.axes.Axes` wrapper for crystallographic pole figures.
 16
 17    .. note::
 18        Projections are not performed automatically using default methods like
 19        `scatter` or `plot`. To actually plot the pole figures, use `polefigure`.
 20
 21    """
 22
 23    name = "pydrex.polefigure"
 24
 25    def _prep_polefig_axis(self, ref_axes="xz"):
 26        """Set various options of a matplotlib `Axes` to prepare for a pole figure.
 27
 28        Use a two-letter string for `ref_axes`.
 29        These letters will be used for the horizontal and vertical labels, respectively.
 30
 31        """
 32        self.set_axis_off()
 33        self.set_aspect("equal")
 34        _circle_points = np.linspace(0, np.pi * 2, 100)
 35        self.plot(
 36            np.cos(_circle_points),
 37            np.sin(_circle_points),
 38            linewidth=0.25,
 39            color=mpl.rcParams["axes.edgecolor"],
 40        )
 41        self.axhline(0, color=mpl.rcParams["grid.color"], alpha=0.5)
 42        self.text(
 43            1.0,
 44            0.4,
 45            ref_axes[0],
 46            verticalalignment="center",
 47            transform=self.transAxes,
 48            fontsize="x-small",
 49        )
 50        self.axvline(0, color=mpl.rcParams["grid.color"], alpha=0.5)
 51
 52        self.text(
 53            0.6,
 54            1.0,
 55            ref_axes[1],
 56            horizontalalignment="center",
 57            transform=self.transAxes,
 58            fontsize="x-small",
 59        )
 60
 61    def polefigure(
 62        self,
 63        data: np.ndarray,
 64        density: bool = False,
 65        ref_axes: str = "xz",
 66        hkl=[1, 0, 0],
 67        density_kwargs: dict | None = None,
 68        **kwargs,
 69    ):
 70        """Plot pole figure of crystallographic texture.
 71
 72        - `data` — Nx3x3 array of orientation matrices
 73        - `density` (optional) — plot contoured pole figures, False by default
 74        - `ref_axes` (optional) — letters specifying the horizontal and vertical axes of
 75          the pole figure, and respective labels
 76        - `hkl` (optional) — crystallographic axis (one of the slip directions of
 77          the mineral phase, e.g. [1, 0, 0], [0, 1, 0] or [0, 0, 1])
 78        - `density_kwargs` (optional) — keyword arguments to pass to
 79          `pydrex.stats.point_density` if `density=True`
 80
 81        Any additional keyword arguments are passed to either `tripcolor` if
 82        `density=True` or `scatter` if `density=False`.
 83
 84        """
 85        if density_kwargs is None:
 86            density_kwargs = {}
 87
 88        self._prep_polefig_axis(ref_axes=ref_axes)
 89
 90        if density:
 91            x, y, z = _stats.point_density(
 92                *_geo.poles(data, hkl=hkl, ref_axes=ref_axes), **density_kwargs
 93            )
 94            return self.tripcolor(
 95                x.ravel(),
 96                y.ravel(),
 97                z.ravel(),
 98                shading=kwargs.pop("shading", "gouraud"),
 99                **kwargs,
100            )
101        else:
102            return self.scatter(
103                *_geo.lambert_equal_area(
104                    *_geo.poles(data, hkl=hkl, ref_axes=ref_axes),
105                ),
106                s=kwargs.pop("s", 1),
107                c=kwargs.pop("c", mpl.rcParams["axes.edgecolor"]),
108                marker=kwargs.pop("marker", "."),
109                alpha=kwargs.pop("alpha", 0.33),
110                zorder=kwargs.pop("zorder", 11),
111                **kwargs,
112            )
113
114
115register_projection(PoleFigureAxes)
class PoleFigureAxes(matplotlib.axes._axes.Axes):
 13class PoleFigureAxes(mplax.Axes):
 14    """Axes class designed for crystallographic pole figures.
 15
 16    Thin `matplotlib.axes.Axes` wrapper for crystallographic pole figures.
 17
 18    .. note::
 19        Projections are not performed automatically using default methods like
 20        `scatter` or `plot`. To actually plot the pole figures, use `polefigure`.
 21
 22    """
 23
 24    name = "pydrex.polefigure"
 25
 26    def _prep_polefig_axis(self, ref_axes="xz"):
 27        """Set various options of a matplotlib `Axes` to prepare for a pole figure.
 28
 29        Use a two-letter string for `ref_axes`.
 30        These letters will be used for the horizontal and vertical labels, respectively.
 31
 32        """
 33        self.set_axis_off()
 34        self.set_aspect("equal")
 35        _circle_points = np.linspace(0, np.pi * 2, 100)
 36        self.plot(
 37            np.cos(_circle_points),
 38            np.sin(_circle_points),
 39            linewidth=0.25,
 40            color=mpl.rcParams["axes.edgecolor"],
 41        )
 42        self.axhline(0, color=mpl.rcParams["grid.color"], alpha=0.5)
 43        self.text(
 44            1.0,
 45            0.4,
 46            ref_axes[0],
 47            verticalalignment="center",
 48            transform=self.transAxes,
 49            fontsize="x-small",
 50        )
 51        self.axvline(0, color=mpl.rcParams["grid.color"], alpha=0.5)
 52
 53        self.text(
 54            0.6,
 55            1.0,
 56            ref_axes[1],
 57            horizontalalignment="center",
 58            transform=self.transAxes,
 59            fontsize="x-small",
 60        )
 61
 62    def polefigure(
 63        self,
 64        data: np.ndarray,
 65        density: bool = False,
 66        ref_axes: str = "xz",
 67        hkl=[1, 0, 0],
 68        density_kwargs: dict | None = None,
 69        **kwargs,
 70    ):
 71        """Plot pole figure of crystallographic texture.
 72
 73        - `data` — Nx3x3 array of orientation matrices
 74        - `density` (optional) — plot contoured pole figures, False by default
 75        - `ref_axes` (optional) — letters specifying the horizontal and vertical axes of
 76          the pole figure, and respective labels
 77        - `hkl` (optional) — crystallographic axis (one of the slip directions of
 78          the mineral phase, e.g. [1, 0, 0], [0, 1, 0] or [0, 0, 1])
 79        - `density_kwargs` (optional) — keyword arguments to pass to
 80          `pydrex.stats.point_density` if `density=True`
 81
 82        Any additional keyword arguments are passed to either `tripcolor` if
 83        `density=True` or `scatter` if `density=False`.
 84
 85        """
 86        if density_kwargs is None:
 87            density_kwargs = {}
 88
 89        self._prep_polefig_axis(ref_axes=ref_axes)
 90
 91        if density:
 92            x, y, z = _stats.point_density(
 93                *_geo.poles(data, hkl=hkl, ref_axes=ref_axes), **density_kwargs
 94            )
 95            return self.tripcolor(
 96                x.ravel(),
 97                y.ravel(),
 98                z.ravel(),
 99                shading=kwargs.pop("shading", "gouraud"),
100                **kwargs,
101            )
102        else:
103            return self.scatter(
104                *_geo.lambert_equal_area(
105                    *_geo.poles(data, hkl=hkl, ref_axes=ref_axes),
106                ),
107                s=kwargs.pop("s", 1),
108                c=kwargs.pop("c", mpl.rcParams["axes.edgecolor"]),
109                marker=kwargs.pop("marker", "."),
110                alpha=kwargs.pop("alpha", 0.33),
111                zorder=kwargs.pop("zorder", 11),
112                **kwargs,
113            )

Axes class designed for crystallographic pole figures.

Thin matplotlib.axes.Axes wrapper for crystallographic pole figures.

Projections are not performed automatically using default methods like scatter or plot. To actually plot the pole figures, use polefigure.

name = 'pydrex.polefigure'
def polefigure( self, data: numpy.ndarray, density: bool = False, ref_axes: str = 'xz', hkl=[1, 0, 0], density_kwargs: dict | None = None, **kwargs):
 62    def polefigure(
 63        self,
 64        data: np.ndarray,
 65        density: bool = False,
 66        ref_axes: str = "xz",
 67        hkl=[1, 0, 0],
 68        density_kwargs: dict | None = None,
 69        **kwargs,
 70    ):
 71        """Plot pole figure of crystallographic texture.
 72
 73        - `data` — Nx3x3 array of orientation matrices
 74        - `density` (optional) — plot contoured pole figures, False by default
 75        - `ref_axes` (optional) — letters specifying the horizontal and vertical axes of
 76          the pole figure, and respective labels
 77        - `hkl` (optional) — crystallographic axis (one of the slip directions of
 78          the mineral phase, e.g. [1, 0, 0], [0, 1, 0] or [0, 0, 1])
 79        - `density_kwargs` (optional) — keyword arguments to pass to
 80          `pydrex.stats.point_density` if `density=True`
 81
 82        Any additional keyword arguments are passed to either `tripcolor` if
 83        `density=True` or `scatter` if `density=False`.
 84
 85        """
 86        if density_kwargs is None:
 87            density_kwargs = {}
 88
 89        self._prep_polefig_axis(ref_axes=ref_axes)
 90
 91        if density:
 92            x, y, z = _stats.point_density(
 93                *_geo.poles(data, hkl=hkl, ref_axes=ref_axes), **density_kwargs
 94            )
 95            return self.tripcolor(
 96                x.ravel(),
 97                y.ravel(),
 98                z.ravel(),
 99                shading=kwargs.pop("shading", "gouraud"),
100                **kwargs,
101            )
102        else:
103            return self.scatter(
104                *_geo.lambert_equal_area(
105                    *_geo.poles(data, hkl=hkl, ref_axes=ref_axes),
106                ),
107                s=kwargs.pop("s", 1),
108                c=kwargs.pop("c", mpl.rcParams["axes.edgecolor"]),
109                marker=kwargs.pop("marker", "."),
110                alpha=kwargs.pop("alpha", 0.33),
111                zorder=kwargs.pop("zorder", 11),
112                **kwargs,
113            )

Plot pole figure of crystallographic texture.

  • data — Nx3x3 array of orientation matrices
  • density (optional) — plot contoured pole figures, False by default
  • ref_axes (optional) — letters specifying the horizontal and vertical axes of the pole figure, and respective labels
  • hkl (optional) — crystallographic axis (one of the slip directions of the mineral phase, e.g. [1, 0, 0], [0, 1, 0] or [0, 0, 1])
  • density_kwargs (optional) — keyword arguments to pass to pydrex.stats.point_density if density=True

Any additional keyword arguments are passed to either tripcolor if density=True or scatter if density=False.

def set( self, *, 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>, 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>):
148        cls.set = lambda self, **kwargs: Artist.set(self, **kwargs)

Set multiple properties at once.

Supported properties are

Properties: adjustable: {'box', 'datalim'} agg_filter: 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 alpha: scalar or None anchor: (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...} animated: bool aspect: {'auto', 'equal'} or float autoscale_on: bool autoscalex_on: unknown autoscaley_on: unknown axes_locator: Callable[[Axes, Renderer], Bbox] axisbelow: bool or 'line' box_aspect: float or None clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None facecolor or fc: :mpltype:color figure: ~matplotlib.figure.Figure forward_navigation_events: bool or "auto" frame_on: bool gid: str in_layout: bool label: object mouseover: bool navigate: bool navigate_mode: unknown path_effects: list of .AbstractPathEffect picker: None or bool or float or callable position: [left, bottom, width, height] or ~matplotlib.transforms.Bbox prop_cycle: ~cycler.Cycler rasterization_zorder: float or None rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None subplotspec: unknown title: str transform: ~matplotlib.transforms.Transform url: str visible: bool xbound: (lower: float, upper: float) xlabel: str xlim: (left: float, right: float) xmargin: float greater than -0.5 xscale: unknown xticklabels: unknown xticks: unknown ybound: (lower: float, upper: float) ylabel: str ylim: (bottom: float, top: float) ymargin: float greater than -0.5 yscale: unknown yticklabels: unknown yticks: unknown zorder: float

Inherited Members
matplotlib.axes._base._AxesBase
_AxesBase
axes
spines
fmt_xdata
fmt_ydata
get_subplotspec
set_subplotspec
get_gridspec
get_window_extent
set_figure
viewLim
get_xaxis_transform
get_xaxis_text1_transform
get_xaxis_text2_transform
get_yaxis_transform
get_yaxis_text1_transform
get_yaxis_text2_transform
get_position
set_position
reset_position
set_axes_locator
get_axes_locator
sharex
sharey
clear
cla
ArtistList
artists
collections
images
lines
patches
tables
texts
get_facecolor
set_facecolor
set_prop_cycle
get_aspect
set_aspect
get_adjustable
set_adjustable
get_box_aspect
set_box_aspect
get_anchor
set_anchor
get_data_ratio
apply_aspect
axis
get_legend
get_images
get_lines
get_xaxis
get_yaxis
get_xgridlines
get_xticklines
get_ygridlines
get_yticklines
has_data
add_artist
add_child_axes
add_collection
add_image
add_line
add_patch
add_table
add_container
relim
update_datalim
in_axes
get_autoscalex_on
get_autoscaley_on
set_autoscalex_on
set_autoscaley_on
get_autoscale_on
set_autoscale_on
use_sticky_edges
get_xmargin
get_ymargin
set_xmargin
set_ymargin
margins
set_rasterization_zorder
get_rasterization_zorder
autoscale
autoscale_view
draw
draw_artist
redraw_in_frame
get_frame_on
set_frame_on
get_axisbelow
set_axisbelow
grid
ticklabel_format
locator_params
tick_params
set_axis_off
set_axis_on
get_xlabel
set_xlabel
invert_xaxis
xaxis_inverted
get_xbound
set_xbound
get_xlim
set_xlim
get_xscale
set_xscale
get_xticks
set_xticks
get_xmajorticklabels
get_xminorticklabels
get_xticklabels
set_xticklabels
get_ylabel
set_ylabel
invert_yaxis
yaxis_inverted
get_ybound
set_ybound
get_ylim
set_ylim
get_yscale
set_yscale
get_yticks
set_yticks
get_ymajorticklabels
get_yminorticklabels
get_yticklabels
set_yticklabels
xaxis_date
yaxis_date
format_xdata
format_ydata
format_coord
minorticks_on
minorticks_off
can_zoom
can_pan
get_navigate
set_navigate
get_navigate_mode
set_navigate_mode
start_pan
end_pan
drag_pan
get_children
contains
contains_point
get_default_bbox_extra_artists
get_tightbbox
twinx
twiny
get_shared_x_axes
get_shared_y_axes
label_outer
set_forward_navigation_events
get_forward_navigation_events
get_fc
set_fc
matplotlib.axes._axes.Axes
get_title
set_title
get_legend_handles_labels
legend
inset_axes
indicate_inset
indicate_inset_zoom
secondary_xaxis
secondary_yaxis
text
annotate
axhline
axvline
axline
axhspan
axvspan
hlines
vlines
eventplot
plot
plot_date
loglog
semilogx
semilogy
acorr
xcorr
step
bar
barh
bar_label
broken_barh
stem
pie
errorbar
boxplot
bxp
scatter
hexbin
arrow
quiverkey
quiver
barbs
fill
fill_between
fill_betweenx
imshow
pcolor
pcolormesh
pcolorfast
contour
contourf
clabel
hist
stairs
hist2d
ecdf
psd
csd
magnitude_spectrum
angle_spectrum
phase_spectrum
cohere
specgram
spy
matshow
violinplot
violin
table
stackplot
streamplot
tricontour
tricontourf
tripcolor
triplot
matplotlib.artist.Artist
zorder
stale_callback
figure
clipbox
remove
have_units
convert_xunits
convert_yunits
stale
add_callback
remove_callback
pchanged
is_transform_set
set_transform
get_transform
pickable
pick
set_picker
get_picker
get_url
set_url
get_gid
set_gid
get_snap
set_snap
get_sketch_params
set_sketch_params
set_path_effects
get_path_effects
get_figure
set_clip_box
set_clip_path
get_alpha
get_visible
get_animated
get_in_layout
get_clip_on
get_clip_box
get_clip_path
get_transformed_clip_path_and_affine
set_clip_on
get_rasterized
set_rasterized
get_agg_filter
set_agg_filter
set_alpha
set_visible
set_animated
set_in_layout
get_label
set_label
get_zorder
set_zorder
sticky_edges
update_from
properties
update
findobj
get_cursor_data
format_cursor_data
get_mouseover
set_mouseover
mouseover