Plotly Type Stubs

0.1.3 · active · verified Mon Apr 13

plotly-stubs is a stub-only package providing static type annotations for the Plotly Python graphing library. It enables type checkers like Mypy to validate Plotly-related code, improving code quality and maintainability. Currently, it is in 'Beta' development status.

Warnings

Install

Imports

Quickstart

To use plotly-stubs, simply install it alongside `plotly`. Type checkers will automatically pick up the stub files. The example demonstrates a function that creates a Plotly figure with type hints, leveraging the stubs for static analysis.

import plotly.express as px
import pandas as pd
from plotly.graph_objects import Figure # Type hint for the return

def create_population_chart(df: pd.DataFrame) -> Figure:
    """Creates a population scatter plot using Plotly Express."""
    fig = px.scatter(
        df,
        x="gdpPercap",
        y="lifeExp",
        size="pop",
        color="continent",
        hover_name="country",
        log_x=True,
        size_max=60
    )
    return fig

# Example usage (assuming 'gapminder' dataset is available, e.g., from px.data.gapminder())
# df_gapminder = px.data.gapminder()
# fig = create_population_chart(df_gapminder)
# fig.show()

view raw JSON →