Plotly Express
Plotly Express (often imported as `px`) is a high-level Python visualization library, designed as a terse, consistent, and easy-to-learn wrapper for Plotly.py. It simplifies the creation of interactive charts with single-function calls, offering over 30 functions for various plot types, including statistical, scientific, and geographical charts. While `plotly-express` on PyPI is at version 0.4.1, the core functionality is now a built-in module, `plotly.express`, within the main `plotly` library (version 6.x.x+), which is actively developed and maintained.
Warnings
- gotcha The standalone `plotly-express` PyPI package (version 0.4.1) is now largely a wrapper that re-exports `plotly.express`, which is a module built directly into the main `plotly` library (versions 4.0 and higher). Users typically install `plotly` directly to get `plotly.express`.
- deprecated Mapbox-based traces (`scatter_mapbox`, `line_mapbox`, `choropleth_mapbox`, `density_mapbox`) are deprecated in `plotly.py` version 6 and will be removed in a future release. They rely on Mapbox tokens and are being replaced.
- breaking Transforms, which were deprecated in `plotly.py` v5, have been completely removed in `plotly.py` v6. Functionality previously achieved with transforms must now be handled by preprocessing data with a dataframe library.
- breaking Several layout attributes for titles (`titlefont`, `titleposition`, `titleside`, `titleoffset`) have been removed in `plotly.py` v6. These were part of the older layout structure.
- gotcha Plotly Express functions are primarily designed for 'tidy' or long-form dataframes. While some 2D Cartesian functions support wide-form data, using wide-form data may not expose all of Plotly Express's flexible parameter mapping capabilities.
- gotcha While Plotly Express offers a high-level API for rapid plotting, it provides less fine-grained control over every plot detail compared to `plotly.graph_objects`. For highly customized or complex interactive figures, direct use of `plotly.graph_objects` might be necessary.
Install
-
pip install plotly-express -
pip install plotly
Imports
- plotly.express
import plotly.express as px
Quickstart
import plotly.express as px import pandas as pd # Use a built-in dataset for a quick example df = px.data.iris() # Create a scatter plot fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", title="Iris Sepal Width vs Length") # Display the figure fig.show()