Skip to Content
DataCards 2.2.4 is released 🎉
DocumentationPlotting Library

Plotting Library

Utilities available under datacards.utilities.plotting

The plotting library is a collection of helper functions for creating plots using matplotlib. It is used by the various matplotlib cards.

Area Calculation

plot_area

def plot_area( rows: int, columns: int, dpi: float = 100.0, value_in_card: bool = False, unit_in_card: bool = False ) -> Tuple[float, float]:

Calculates the appropriate figure size for datacard plots.

Parameters:

  • rows: Number of rows in the plot
  • columns: Number of columns in the plot
  • dpi: Dots per inch (default: 100.0)
  • value_in_card: Whether value is shown in card (default: False)
  • unit_in_card: Whether unit is shown in card (default: False)

Returns:

  • Tuple[float, float]: Width and height of the figure

Basic Plots

boxplot

def boxplot( x: List[float], thumbnail: bool ) -> Tuple[plt.Figure, plt.Axes]:

Creates a boxplot visualization.

Parameters:

  • x: List of numerical values to plot
  • thumbnail: Whether to create a thumbnail version

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

histogram

def histogram( x: List[float], x_label: str, y_label: str, kernel_density: bool, thumbnail: bool ) -> Tuple[plt.Figure, plt.Axes]:

Creates a histogram with optional kernel density estimation.

Parameters:

  • x: List of numerical values to plot
  • x_label: Label for the x-axis
  • y_label: Label for the y-axis
  • kernel_density: Whether to show kernel density estimation
  • thumbnail: Whether to create a thumbnail version

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

scatterplot

def scatterplot( x: List[float], y: List[float], x_label: str, y_label: str, thumbnail: bool, flag: Optional[List[str]] = None ) -> Tuple[plt.Figure, plt.Axes]:

Creates a scatter plot with optional color coding.

Parameters:

  • x: List of x-coordinates
  • y: List of y-coordinates
  • x_label: Label for the x-axis
  • y_label: Label for the y-axis
  • thumbnail: Whether to create a thumbnail version
  • flag: Optional list of status flags (‘neutral’, ‘lessen’, ‘warning’, ‘danger’, ‘success’)

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

lineplot

def lineplot( x: List[float], y: List[float], x_label: str, y_label: str, thumbnail: bool, flag: Optional[List[str]] = None, majorante_x: Optional[List[float]] = None, majorante_y: Optional[List[float]] = None, minorante_x: Optional[List[float]] = None, minorante_y: Optional[List[float]] = None, **kwargs ) -> Tuple[plt.Figure, plt.Axes]:

Creates a line plot with optional confidence intervals.

Parameters:

  • x: List of x-coordinates
  • y: List of y-coordinates
  • x_label: Label for the x-axis
  • y_label: Label for the y-axis
  • thumbnail: Whether to create a thumbnail version
  • flag: Optional list of status flags
  • majorante_x: Optional x-coordinates for upper bound
  • majorante_y: Optional y-coordinates for upper bound
  • minorante_x: Optional x-coordinates for lower bound
  • minorante_y: Optional y-coordinates for lower bound
  • **kwargs: Additional matplotlib plotting parameters

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

barplot

def barplot( basket_labels: List[str], grp_value_dictionary: Dict[str, List[float]], y_label: str, show_legend: bool = True ) -> Tuple[plt.Figure, plt.Axes]:

Creates a grouped bar plot along several baskets (e.g. years).

Parameters:

  • basket_labels: List of labels for each group
  • grp_value_dictionary: Dictionary mapping group names to their values
  • y_label: Label for the y-axis
  • show_legend: Whether to show the legend (default: True)

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

Specialized Plots

speedometer

def speedometer( x: float, limits: List[float], thumbnail: bool, x_label: str ) -> Tuple[plt.Figure, plt.Axes]:

Creates a speedometer-style gauge visualization.

Parameters:

  • x: Current value to display
  • limits: List of limit values for the gauge
  • thumbnail: Whether to create a thumbnail version
  • x_label: Label for the x-axis

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

traffic_lights

def traffic_lights( red: bool, yellow: bool, green: bool ) -> Tuple[plt.Figure, plt.Axes]:

Creates a traffic light visualization.

Parameters:

  • red: Whether red light is on
  • yellow: Whether yellow light is on
  • green: Whether green light is on

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

donutplot

def donutplot( x: List[float], labels: List[str], thumbnail: bool ) -> Tuple[plt.Figure, plt.Axes]:

Creates a donut/pie chart visualization.

Parameters:

  • x: List of values for each segment
  • labels: List of labels for each segment
  • thumbnail: Whether to create a thumbnail version

Returns:

  • Tuple[plt.Figure, plt.Axes]: Figure and axes objects containing the plot

flight_envelope_bg

def flight_envelope_bg( polyMACHdf: pd.DataFrame, polyDTAMBdf: pd.DataFrame, thumbnail: bool ) -> Tuple[plt.Figure, dict[str, plt.Axes]]:

Used to create the special flight envelope plot. Draws a figure with two named axes DTAMB and MACH with shared ALTITUDE-axes.

Parameters:

  • polyMACHdf: DataFrame containing MACH polygon vertices
  • polyDTAMBdf: DataFrame containing DTAMB polygon vertices
  • thumbnail: Whether to create a thumbnail version

Returns:

  • Tuple[plt.Figure, dict[str, plt.Axes]]: Figure and dictionary of axes objects containing the plot

Color Mapping

The library uses the following color scheme for status flags:

  • Danger: #FF0B5F (Red)
  • Warning: #FFD90B (Yellow)
  • Success: #0BFF85 (Green)
  • Neutral: #E5E5E5 (Light Grey)
  • Lessen: #AAAAAA (Dark Grey)
Last updated on