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:

Colorbar

hsr4hci.plotting.adjust_luminosity(color, amount=1.4)[source]#

Adjust the luminosity of the given color by the amount.

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; for amount < 1, the color is darkened. By default, colors are lightened by 40%.

Returns:

An RGB tuple describing the luminosity-adjusted input color.

Return type:

Tuple[float, float, float]

hsr4hci.plotting.disable_ticks(ax)[source]#

Disable the ticks and labels on the given matplotlib ax. This is similar to calling ax.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 the bad_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_color of the color map; that is, the color used, for example, for NaN values in matplotlib.pyplot.imshow() plots.

Returns:

A matplotlib colormap with the desired bad_color.

Return type:

Union[Colormap, LinearSegmentedColormap, ListedColormap]

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

Parameters:

color (Union[str, Tuple[float, float, float], Tuple[float, float, float, float]]) – A valid matplotlib color.

Returns:

A ListedColormap, which gradually goes from transparent to the given target color.

Return type:

ListedColormap

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_scalebar is 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. If positions is 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

  1. the current matplotlib figure,

  2. the current axis containing the plot of the frame, and

  3. the colorbar object (or None, if no colorbar was added).

Return type:

Tuple[Figure, Axes, Optional[Colorbar]]

hsr4hci.plotting.set_fontsize(ax, fontsize)[source]#

Set the fontsize for all labels (title, x- and y-label, and tick labels) of a target ax at once.

Parameters:
  • ax (Axes) – The ax which contains the plot.

  • fontsize (int) – The target font size for the labels.

Return type:

None

hsr4hci.plotting.zerocenter_imshow(ax)[source]#

Make sure that the (vmin, vmax) range of the imshow() plot in the given ax object is symmetric around zero.

Parameters:

ax (Axes) – The ax which contains the plot.

Return type:

None

hsr4hci.plotting.zerocenter_plot(ax, which)[source]#

Make sure that the xlim or ylim range of the plot object in the given ax object is symmetric around zero.

Parameters:
  • ax (Axes) – The ax which contains the plot.

  • which (str) – Which axis to center around zero (β€œx” or β€œy”).

Return type:

None