Overview of Plotly Express (PX)
mainPlotly Express (plotly.express, commonly imported as px) is a high-level, terse, and consistent API for creating figures. It is the recommended starting point for most common visualizations.
Key characteristics:
- Single Function Calls: Most figures can be created with a single function call.
- Graph Objects Integration: Every PX function returns a
plotly.graph_objects.Figureinstance, allowing you to use standard methods like.update_layout()or.add_trace()for fine-grained customization. - Consistent API: The design allows for easy switching between different chart types (e.g., from scatter to bar) during data exploration.
- Built-in Resources: Access demo datasets via
px.dataand color scales/sequences viapx.colors.
import plotly.express as px
# Example: Basic scatter plot using built-in data
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.show()