Skip to main content
Instantiate a dashboard in PNG format from a matplotlib figure or bytes inside a Python dashboard file. This class can be imported from the squirrels.dashboards or the squirrels module.

Constructor

Creates a PngDashboard object.
def __init__(
    self, content: matplotlib.figure.Figure | io.BytesIO | bytes
) -> None:

Example

Here’s an example of creating a PNG dashboard using matplotlib:
from squirrels.dashboards import PngDashboard
from squirrels.arguments import DashboardArgs
import matplotlib.pyplot as plt
import polars as pl

async def main(sqrl: DashboardArgs) -> PngDashboard:
    # Get dataset
    df = await sqrl.dataset("sales_data")
    
    # Create matplotlib figure
    fig, ax = plt.subplots(figsize=(10, 6))
    
    # Plot data
    pandas_df = df.to_pandas()
    pandas_df.plot(x='date', y='revenue', ax=ax)
    ax.set_title('Sales Revenue Over Time')
    ax.set_xlabel('Date')
    ax.set_ylabel('Revenue ($)')
    
    # Return as PngDashboard
    return PngDashboard(content=fig)