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 plotcolumns
: Number of columns in the plotdpi
: 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 plotthumbnail
: 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 plotx_label
: Label for the x-axisy_label
: Label for the y-axiskernel_density
: Whether to show kernel density estimationthumbnail
: 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-coordinatesy
: List of y-coordinatesx_label
: Label for the x-axisy_label
: Label for the y-axisthumbnail
: Whether to create a thumbnail versionflag
: 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-coordinatesy
: List of y-coordinatesx_label
: Label for the x-axisy_label
: Label for the y-axisthumbnail
: Whether to create a thumbnail versionflag
: Optional list of status flagsmajorante_x
: Optional x-coordinates for upper boundmajorante_y
: Optional y-coordinates for upper boundminorante_x
: Optional x-coordinates for lower boundminorante_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 groupgrp_value_dictionary
: Dictionary mapping group names to their valuesy_label
: Label for the y-axisshow_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 displaylimits
: List of limit values for the gaugethumbnail
: Whether to create a thumbnail versionx_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 onyellow
: Whether yellow light is ongreen
: 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 segmentlabels
: List of labels for each segmentthumbnail
: 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 verticespolyDTAMBdf
: DataFrame containing DTAMB polygon verticesthumbnail
: 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)