The SunburstPlot Class#

class sunburst.plot.SunburstPlot(input_pv: ~typing.Dict[~sunburst.path.Path, float], axes: ~matplotlib.axes._axes.Axes | None = None, origin=(0.0, 0.0), cmap=<matplotlib.colors.LinearSegmentedColormap object>, base_ring_width=0.4, base_edge_color=(0, 0, 0, 1), base_line_width=0.75, plot_center=False, plot_minimal_angle=0, label_minimal_angle=0, order='value reverse', base_textbox_props=None)[source]#

The central class of the suburst package.

Usage:
  • Initialize SunburstPlot object

  • Redefine attributes or methods

  • Run SunburstPlot.plot()

All of the following attributes can be set
  • as keyword argument during initialisation

  • after initialization, but before calling prepare_data() or plot().

Arguments starting with the prefix base can also be defined dynamically (usually depending on the path to which a wedge correspond) by redefining the method with the same name without the prefix base.

E.g. the attribute self.base_wedge_width corresponds to the initialization keyword argument base_wedge_width and to the method wedge_width():

def wedge_width(self, path: Path) -> float:
    return self.base_ring_width

Almost all of the methods can (or are meant to) be redefined. Those which should be handled more carefully are designated by a leading underscore.

pathvalues#

pathvalues of type MutuableMapping[Path, float]

axes#
origin#

Coordinates of the center of the pie chart as tuple

cmap#

Colormap: Controls the coloring based on the angle.

base_ring_width#

Default width of each ring/wedge.

base_edge_color#

Default edge color of the wedges.

base_line_width#

Default line width of the wedges.

plot_center#

Plot a circle in the middle corresponding to the total of all paths.

plot_minimal_angle#

Plot only wedges with an angle bigger than plot_minimal_angle

label_minimal_angle#

Only label wedges with an angle bigger than this value

order#

string with syntax keep|value|key [reverse], e.g. “key reverse” (default) or “value” or “reverse” controlling in which order the wedges will be created

  • keep: Keep the order of the supplied pathvalues dictionary (for this to work, use a dictionary subclass that supports ordering, i.e. collections.OrderedDict). This is the default, but explicitly stating it, will warn you if you supply a normal dict for pathvalues.

  • value: Sort values from small to big

  • key: Sort paths alphabetically

  • reversed: take the order specified by one of the above options (or none) and reverse it.

base_textbox_props#

Properties of the textbox (bbox) that annotating the wedge corresponding to path. See http://matplotlib.org/users/annotations_guide.html

prepare_data() None[source]#

Sets up auxiliary variables.

Most of the actual computations are defined as functions for better testing (in file calc.py).

_is_outmost(path: Path) bool[source]#

Returns True if the wedge corresponding to path is the “outmost” wedge, i.e. there is no descendant of path.

wedge_width(path: Path) float[source]#

The width of the wedge corresponding to path.

This method is meant to be redefined. Per default it only returns base_wedge_width.

wedge_spacing(path: Path) Tuple[float, float][source]#

The radial space before the wedge corresponding to path and after.

E.g. if wedge_space(some/path) = 0.1, 0.2, then this shifts the wedge corresponding to some/path by 0.1 radially away from the center and all wedges corresponding to ancestors of some/path (e.g. some/path/child, some/path/child/grandchild) by 0.2 radially away from the center.

_wedge_outer_radius(path: Path) float[source]#

The outer radius of the wedge corresponding to a path.

Instead of redefining this method, adapt wedge_width() resp. wedge_width().

_wedge_inner_radius(path: Path) float[source]#

The inner radius of the wedge corresponding to a path.

Instead of redefining this method, adapt wedge_width() resp. wedge_width().

_wedge_mid_radius(path: Path) float[source]#

The radius of the middle of the wedge corresponding to a path.

Instead of redefining this method, adapt wedge_width() resp. wedge_width().

edge_color(path: Path) Tuple[float, float, float, float][source]#

The line color of the wedge corresponding to path.

This method is meant to be redefined. Per default it only returns base_edge_color.

line_width(path: Path) float[source]#

The line width of the wedge corresponding to path.

This method is meant to be redefined. Per default it only returns base_line_width.

face_color(path: Path) Tuple[float, float, float, float][source]#

The color of the wedge corresponding to path.

Per default, the color is calculated by the value of cmap at the mid-angle of the wedge. The color of an inner circle (corresponding to an empty path) is always set to be white. Colors a slightly brightened with increasing level.

alpha(path: Path) float[source]#

The alpha value of the wedge corresponding to path.

This method is meant to be redefined. Per default it only returns 1.

textbox_props(path: Path, text_type: str) Dict[source]#

Properties of the textbox (bbox) that annotating the wedge corresponding to path.

This method is meant to be redefined. Per default it is independent of the arguments.

Parameters:
  • path (Path) – path

  • text_type (str) – Position type of the text box: “tangential”, “radial”, etc.

Returns:

Dictionary of keyword properties for the bbox option of the matplotlib.pyplot.text() function. See http://matplotlib.org/users/annotations_guide.html

format_path_text(path) str[source]#

Returns a string representation for path which is used to annotate the corresponding wedge.

format_value_text(value: float) str[source]#

Returns a string representation of the value corresponding to path which is used to annotate the wedge corresponding to path.

format_text(path: Path) str[source]#

Returns a string used annotate the wedge corresponding to path.

Most modifications of the annotations can be made by redefining format_path_text() or format_value_text(), this method combines both of those methods.

_radial_text(path: Path) None[source]#

Adds a radially rotated annotation for the wedge corresponding to path to the axes.

_tangential_text(path: Path) None[source]#

Adds a tangentially rotated annotation for the wedge corresponding to path to the axes.

_add_annotation(path)[source]#

Adds annotation to the wedge corresponding to path.

plot(setup_axes=False, interactive=False) None[source]#

Method that combines several others, to do all necessary preparations and add the plot to the axes self.axes.

Parameters:
  • setup_axes (bool) – Does some basic setup for the axes (autoscale, margins, etc.). It won’t always be the perfect setup but it saves writing a few lines.

  • interactive (bool) – Display label for the wedge under the cursor only.

wedge(path: Path) Wedge[source]#

Generates the patches wedge object corresponding to path.