Plotly in Python: Interactive Charts with Reflex
Plotly is a popular Python graphing library for creating interactive, publication-quality charts. Reflex wraps it with the rx.plotly component so you can embed any Plotly or Plotly Express figure — line charts, scatter plots, histograms, heatmaps, or 3D surface plots — directly into a Python web app with no JavaScript. Because Reflex compiles to a full-stack web app, these charts stay interactive in the browser and can update live from your app state.
fig.show(), use rx.plotly(data=fig) within your UI code to ensure the graph is properly rendered and displayed within the user interfaceBasic Example
Let's create a line graph of life expectancy in Canada.
Plotly Express Chart Types
Plotly Express (plotly.express, imported as px) builds common chart types in a single line of Python, and every figure renders in Reflex with rx.plotly.
Bar Chart
Create a Plotly Express bar chart with px.bar:
Scatter Plot
Create a Plotly scatter plot with px.scatter:
Pie Chart
Create a Plotly pie chart with px.pie:
Heatmap
Create a Plotly heatmap with px.density_heatmap:
Histogram
Create a Plotly histogram with px.histogram:
Box Plot
Create a Plotly box plot with px.box:
Bubble Chart
A bubble chart is a scatter plot in which a third dimension of the data is shown through the size of the markers. Create one with px.scatter by passing a column to the size argument:
Gantt Chart
A Gantt chart is a type of bar chart that illustrates a project schedule: tasks are listed on the vertical axis, time intervals on the horizontal axis, and the width of each bar shows the duration of the activity. Create one with px.timeline:
Sunburst Chart
Sunburst charts visualize hierarchical data spanning outwards radially from root to leaves: the root sits at the center and children are added to the outer rings. Create one with px.sunburst, defining the hierarchy with names and parents:
ExpandCollapse
Funnel Chart
Funnel charts represent data as it moves through the stages of a business process, making them a common Business Intelligence tool for spotting where a process loses volume. Create one with px.funnel:
Locale Configuration
Use locale to localize Plotly number/date formatting and modebar labels:
You can still pass config; when both are provided, locale= is applied as the final locale value.
3D graphing example
Let's create a 3D surface plot of Mount Bruno. This is a slightly more complicated example, but it wraps in Reflex using the same method. In fact, you can wrap any figure using the same approach.
ExpandCollapse
📊 Dataset source: mt_bruno_elevation.csv
Financial Charts
Candlestick Chart
The candlestick chart is a financial chart describing the open, high, low, and close values for a given x coordinate (most likely time): boxes show the spread between open and close, and lines show the spread between low and high. Create one with go.Candlestick:
ExpandCollapse
Waterfall Chart
The waterfall chart visualizes how an initial value is affected by a series of positive and negative changes — for example, a profit and loss statement. Create one with go.Waterfall, marking each value as "relative" or "total" via the measure argument:
ExpandCollapse
Bullet Chart
The bullet chart, designed by Stephen Few as a compact replacement for dashboard gauges and meters, combines a quantitative bar, qualitative ranges (steps), and a performance threshold line in one simple layout. Build one with go.Indicator using the "bullet" gauge shape:
ExpandCollapse
Statistical Charts
Continuous Error Bands
Continuous error bands represent error or uncertainty as a shaded region around a main trace, rather than as discrete whisker-like error bars. Build one with go.Scatter by drawing the main line, then a second trace that walks the upper bound forward and the lower bound in reverse, filled with fill="toself":
ExpandCollapse
Maps
Geo Map
Geo maps are outline-based maps drawn from geographic features rather than map tiles. Figures created with px.scatter_geo, px.line_geo, or px.choropleth — or containing go.Scattergeo or go.Choropleth traces — store their map configuration in the figure's layout.geo object, which you can adjust with update_geos:
Scatter Map
Scatter maps plot markers on a tile-based map, sized and colored by your data — useful for visualizing geographic point data like vehicle locations or store sites. Create one with px.scatter_map (or a go.Scattermap trace for lower-level control):
Tables and Diagrams
Table
Plotly can also render data as an interactive table. Create one with go.Table, passing column headers to header and column data to cells:
Sankey Diagram
A Sankey diagram is a flow diagram in which the width of the arrows is proportional to the flow quantity. Create one with go.Sankey, defining the nodes and the links between them by index:
ExpandCollapse
3D Charts
3D Scatter Plot
3D scatter plots show the relationship between three variables at once, with an optional fourth encoded as color. Create one with px.scatter_3d:
3D Axis
3D figures place their traces in a scene, and each scene axis is configured through the figure's scene layout — set nticks, range, or axis titles per axis. This example renders a go.Mesh3d cloud with custom tick counts and ranges on all three axes:
ExpandCollapse
Plot as State Var
If the figure is set as a state var, it can be updated during run time.
ExpandCollapse
Adding Styles and Layouts
Use update_layout() method to update the layout of your chart. Checkout Plotly Layouts for all layouts props.
ExpandCollapse
API Reference
rx.plotly
Display a plotly graph.
Props
| Prop | Type | Description |
|---|---|---|
data | Figure | The figure to display. This can be a plotly figure or a plotly data json. |
layout | dict | The layout of the graph. |
template | Template | The template for visual appearance of the graph. |
config | dict | The config of the graph. |
locale | str | The locale code used for Plotly formatting and modebar labels. |
use_resize_handler | bool | If true, the graph will resize when the window is resized. |