cantuccio.visuals module

visuals.py

This module contains some plotting utility functions for cantuccio corner plots.

cantuccio.visuals.chain_cmap(color)[source]

Linear colormap from fully transparent to color; good for hist2d/hexbin.

Parameters:

color (str) – The color to use for the colormap.

Returns:

The colormap.

Return type:

LinearSegmentedColormap

cantuccio.visuals.get_paper_style(journal='prd', cols='onecol', aspect=1.618033988749895)[source]

Get a style list for use with plt.style.context().

Parameters:
  • journal (str, default: 'prd') – Journal name, must be a key in journal_sizes.

  • cols (str, default: 'onecol') – Column key, e.g. ‘onecol’ or ‘twocol’.

  • aspect (float, default: 1.618033988749895) – Height = width / aspect. Defaults to the golden ratio.

Returns:

Two-element list: [style_file_or_name, {“figure.figsize”: (width, height)}].

Return type:

list[str | dict]

cantuccio.visuals.get_stylefile(filename=None)[source]

Get the absolute path to a matplotlib style file in the ‘mplfiles’ directory.

Parameters:

filename (str | None, default: None) – The name of the style file. If None, the default style file is used.

Returns:

The absolute path to the style file.

Return type:

str

cantuccio.visuals.legend_bbox(num_dim)[source]

Return (x, y) in figure-relative coordinates for the corner-plot legend.

Places the legend at the top-left of the upper-right triangle. The target row is num_dim // 3 (capped at 2), and x tracks the leftmost valid upper-triangle column at that row (col = row + 1), so the anchor never lands inside a data panel for any num_dim.

Parameters:

num_dim (int) – Number of corner-plot dimensions.

Returns:

(x, y) in figure-fraction coordinates (top-left legend corner).

Return type:

tuple[float, float]

cantuccio.visuals.reposition_legend(fig, num_dim)[source]

Find the first legend on fig and move it into the upper-right triangle.

Parameters:
  • fig (Figure) – The figure to reposition the legend in.

  • num_dim (int) – Number of corner-plot dimensions.

  • fontsize (int | None) – If given, override the legend font size.

Return type:

None

cantuccio.visuals.scale_font(base, num_dim, ref=2, exp=0.2)[source]

Scale base font size with num_dim using a power law anchored at ref.

Parameters:
  • base (float) – The base font size.

  • num_dim (int) – Number of corner-plot dimensions.

  • ref (int, default: 2) – The reference number of dimensions.

  • exp (float, default: 0.2) – The exponent for the power law.

Returns:

The scaled font size.

Return type:

float