plotting#
Methods for plotting.
- hsr4hci.plotting.add_colorbar_to_ax(img, fig, ax, where='right')[source]#
Add a βniceβ colorbar to an imshow plot.
Original source: https://stackoverflow.com/a/18195921/4100721
- Parameters:
img (AxesImage) β The return of a
matplotlib.pyplot.imshow()command.fig (Figure) β The figure that the plot is part of.
ax (Axes) β The ax which contains the plot.
where (str) β Where to place the colorbar (βleftβ, βrightβ, βtopβ or βbottomβ).
- Returns:
The colorbar that was added to the axis.
- Return type:
- hsr4hci.plotting.adjust_luminosity(color, amount=1.4)[source]#
Adjust the luminosity of the given
colorby theamount.Original source: https://stackoverflow.com/a/49601444/4100721
- Parameters:
color (Union[str, Tuple[float, float, float], Tuple[float, float, float, float]]) β The input color. Can either be a hex string (e.g., β#FF0000β), matplotlib color string (e.g., βC1β or βgreenβ), or an RGB tuple in float format (e.g., (1.0, 0.0, 0.0)).
amount (float) β The amount by how much the input color should be lightened. For
amount> 1, the color gets brighter; foramount< 1, the color is darkened. By default, colors are lightened by 40%.
- Returns:
An RGB tuple describing the luminosity-adjusted input color.
- Return type:
- hsr4hci.plotting.disable_ticks(ax)[source]#
Disable the ticks and labels on the given matplotlib
ax. This is similar to callingax.axis('off'), except that the frame around the plot is preserved.- Parameters:
ax (Axes) β A matplotlib axis.
- Return type:
None
- hsr4hci.plotting.get_cmap(cmap_name='RdBu_r', bad_color='#212121')[source]#
Convenience wrapper around
matplotlib.cm.get_cmap()which allows to also set thebad_color(i.e., the color for NaN values).- Parameters:
cmap_name (str) β The name of a matplotlib color map (e.g., βRdBu_rβ or βviridisβ).
bad_color (str) β A string specifying a color in HTML format: (e.g., β#FF0000β) which will be used as the
bad_colorof the color map; that is, the color used, for example, for NaN values inmatplotlib.pyplot.imshow()plots.
- Returns:
A matplotlib colormap with the desired
bad_color.- Return type:
- hsr4hci.plotting.get_transparent_cmap(color='red')[source]#
Return a colormap that goes from transparent to the target color.
Color maps of this type can be useful, for example, when plotting or overlaying masks, where only the selected pixels should receive a color, while everything else stays
- hsr4hci.plotting.plot_frame(frame, positions, labels, pixscale, figsize=(4.3 / 2.54, 5.0 / 2.54), subplots_adjust=None, aperture_radius=0, label_positions=None, draw_color='darkgreen', scalebar_color='white', cmap='RdBu_r', limits=None, use_logscale=False, add_colorbar=True, add_scalebar=True, add_cardinal_directions=True, scalebar_loc='upper right', file_path=None)[source]#
Plot a single frame (e.g., a signal estimate) with various options.
This function was used to generate most of the result plots in the paper.
- Parameters:
frame (ndarray) β A 2D numpy array of shape (x_size, y_size) containing the frame to be plotted (e.g., a signal estimate).
positions (Sequence[Tuple[float, float]]) β A list of positions (which may be empty). At each position, an aperture is drawn with the given radius.
labels (Sequence[Union[str, float]]) β A list of labels (which may be empty) that are placed next to the apertures drawn at the
positions. Can be used, for example, to add the SNR or FPF to the plot.pixscale (float) β The pixel scale, in units of arcsecond / pixel. Only needed if
add_scalebaris True.figsize (Tuple[float, float]) β A two-tuple (x_size, y_size) containing the size of the figure in inches.
subplots_adjust (Optional[Dict[str, float]]) β Dictionary with parameters that will be passed to
matplotlib.pyplot.subplots_adjust().aperture_radius (float) β The radius of the apertures to be drawn at the given
positions. Ifpositionsis empty, this value is never used.label_positions (Optional[Sequence[str]]) β A list of strings (either βrightβ, βleftβ, βtopβ or βbottomβ) that indicates, for each label where this label should be placed relative to the position that it annotates. Default is βrightβ for all labels.
draw_color (Union[str, Tuple[float, float, float], Tuple[float, float, float, float]]) β The color that is used for drawing the apertures and also labels.
scalebar_color (Union[str, Tuple[float, float, float], Tuple[float, float, float, float]]) β The color that is used for the scale bar and the ticks.
cmap (str) β Name of the color map to be used for plotting.
limits (Optional[Tuple[float, float]]) β A tuple (vmin, vmax) that is used for the plot limits. If None, the limits are estimated from the data.
use_logscale (bool) β Whether to use a (symmetric) log scale.
add_colorbar (bool) β Whether to add a colorbar at the bottom.
add_scalebar (bool) β Whether to add a scale bar and a grid of ticks around the borders of the frame (to better understand the scale of the frame).
add_cardinal_directions (bool) β Whether to add labeled arrows to indicate the cardinal directions (North and East).
scalebar_loc (str) β Location parameter for the scalebar.
file_path (Optional[Union[Path, str]]) β The path at which to save the resulting plot. The path should include the file name plus file ending. If None is given, the plot is not saved.
- Returns:
A 3-tuple containing
the current matplotlib figure,
the current axis containing the plot of the frame, and
the colorbar object (or None, if no colorbar was added).
- Return type:
- hsr4hci.plotting.set_fontsize(ax, fontsize)[source]#
Set the
fontsizefor all labels (title, x- and y-label, and tick labels) of a targetaxat once.
- hsr4hci.plotting.zerocenter_imshow(ax)[source]#
Make sure that the (vmin, vmax) range of the
imshow()plot in the givenaxobject is symmetric around zero.- Parameters:
ax (Axes) β The ax which contains the plot.
- Return type:
None