plotting
plotting
Plotting utilities for planetary image data.
Provides common visualization helpers for planetary science: percentile stretching, grayscale image display, sun direction indicators.
Functions
| Name | Description |
|---|---|
| add_sun_indicator | Add a sun direction indicator to an image plot. Experimental. |
| imshow_gray | Display a grayscale image with optional percentile stretch. |
| imshow_with_sun | Display a grayscale image with a sun direction indicator. Experimental. |
| percentile_stretch | Compute display limits from percentiles, ignoring zeros and NaN. |
add_sun_indicator
plotting.add_sun_indicator(
ax,
sun_azimuth_deg,
position='upper right',
length=0.12,
color='yellow',
inner_color='orange',
)Add a sun direction indicator to an image plot. Experimental.
.. warning::
Experimental. The azimuth-convention handoff is not fully validated: this function expects clockwise-from-image-top (the PDS SUB_SOLAR_AZIMUTH convention for unprojected images), but :meth:planetarypy.spice.spicer.Spicer.solar_azimuth_at returns clockwise-from-north (geographic). They agree only when image-north points up; otherwise you must rotate by the image’s north azimuth before passing the value here. Placement and appearance may change.
The indicator is a small compass glyph (sun ball + arrow) drawn in a corner, pointing toward the sun. It is rendered in axes-fraction coordinates, so it neither rescales the image nor depends on the image’s origin.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| ax | matplotlib.axes.Axes | The axes containing the image. | required |
| sun_azimuth_deg | float | Solar azimuth in degrees, clockwise from image top (see warning). | required |
| position | str | “upper right”, “upper left”, “lower right”, “lower left”. | 'upper right' |
| length | float | Arrow length as a fraction of the axes (default 0.12). | 0.12 |
| color | str | Outer circle and arrow color. | 'yellow' |
| inner_color | str | Inner circle color (smaller, overlaid on outer). | 'orange' |
Returns
| Name | Type | Description |
|---|---|---|
| ax | matplotlib.axes.Axes |
imshow_gray
plotting.imshow_gray(
image,
stretch='1,99',
title=None,
ax=None,
**imshow_kwargs,
)Display a grayscale image with optional percentile stretch.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| image | 2D array | Image data. | required |
| stretch | str or None | Percentile stretch as “lo,hi” (e.g. “1,99”). Use None or “none” to disable. | '1,99' |
| title | str | Plot title. | None |
| ax | matplotlib.axes.Axes | Axes to plot on. Created if not provided. | None |
| **imshow_kwargs | Passed to ax.imshow(). | {} |
Returns
| Name | Type | Description |
|---|---|---|
| ax | matplotlib.axes.Axes |
imshow_with_sun
plotting.imshow_with_sun(
image,
sun_azimuth_deg,
title=None,
ax=None,
stretch='1,99',
sun_position='upper right',
**imshow_kwargs,
)Display a grayscale image with a sun direction indicator. Experimental.
Combines imshow_gray with add_sun_indicator (see that function’s experimental warning about the azimuth convention).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| image | 2D array | Image data. | required |
| sun_azimuth_deg | float | Solar azimuth in degrees, clockwise from image top. | required |
| title | str | Plot title. | None |
| ax | matplotlib.axes.Axes | Axes to plot on. Created if not provided. | None |
| stretch | str or None | Percentile stretch (default “1,99”). None to disable. | '1,99' |
| sun_position | str | Indicator position: “upper right”, “upper left”, etc. | 'upper right' |
| **imshow_kwargs | Passed to ax.imshow(). | {} |
Returns
| Name | Type | Description |
|---|---|---|
| ax | matplotlib.axes.Axes |
percentile_stretch
plotting.percentile_stretch(image, lo=1, hi=99)Compute display limits from percentiles, ignoring zeros and NaN.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| image | array - like | Image data (2D or nD). | required |
| lo | float | Lower and upper percentile (default 1, 99). | 1 |
| hi | float | Lower and upper percentile (default 1, 99). | 1 |
Returns
| Name | Type | Description |
|---|---|---|
| vmin, vmax : float | Display limits suitable for imshow(vmin=, vmax=). Returns (None, None) if no valid pixels. |