Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create an interactive Plotly chart in Python, install Plotly, build a figure with Plotly Express, and display it with fig.show(). Use Plotly Express for common charts; move to graph objects when you need direct control over traces, layout, or specialized subplot compositions. Save as HTML to preserve browser interactions, or export a static image when the destination cannot display an interactive figure.

Install Plotly and display a first chart

Install Plotly with pip or conda, then create and show a figure:

pip install plotly

Alternatively, install from conda-forge:

conda install -c conda-forge plotly
import plotly.express as px

fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.show()

The chart supports browser interactions such as hovering for details, panning, and zooming. In scripts and notebooks, fig.show() uses Plotly’s renderer framework to choose how the figure is displayed. Notebook setup can depend on whether you use JupyterLab, classic Notebook, or another environment; follow the official Plotly getting-started guide for the relevant setup details.

Choose Plotly Express for common charts

Plotly Express, imported as px, is Plotly’s recommended starting point for most common figures. A single function call can create a complete chart, and Plotly describes the library as supporting “over 40 unique chart types” across statistical, financial, geographic, scientific, and 3D use cases. See the Plotly Express documentation for chart types and options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, a bar chart can be built from lists, as above, or from a DataFrame by naming the columns to use:

fig = px.bar(data_frame, x="category", y="value", color="group")
fig.show()

Here, data_frame represents your own DataFrame, and its named columns must exist. Plotly Express returns a plotly.graph_objects.Figure, so you can start with its concise chart-building interface and then customize the resulting figure.

Use graph objects for lower-level control

Choose plotly.graph_objects, commonly imported as go, when you need to work directly with a figure’s traces and layout, use a trace type not covered by Plotly Express, or build a more specialized composition such as mixed-type subplots. The two APIs are complementary rather than mutually exclusive: a Plotly Express figure is already a graph objects figure.

import plotly.graph_objects as go

fig = go.Figure(
    data=[go.Bar(x=["a", "b", "c"], y=[1, 3, 2])]
)
fig.update_layout(title="Example bar chart")
fig.show()

For detailed guidance on figure structure and trace and layout control, see Plotly graph objects and creating and updating figures.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose how to display or share the figure

The right output depends on where the chart will be viewed and whether it needs to remain interactive.

Option Best suited to What to know
fig.show() Viewing a figure during work in a notebook or script Plotly’s renderer framework selects a display method. Available behavior depends on the environment; see Displaying figures in Python.
fig.write_html("plot.html") Sharing a browser-openable interactive figure The saved HTML retains chart interactions. See Interactive HTML export.
Dash Integrating figures into a Python web application Dash is Plotly’s route for building Python web apps; a standalone figure display and an application serve different purposes. Start with the Plotly getting-started guide.
Static image Documents or viewers that accept images but not interactive charts Hover, pan, and zoom are not available in the exported image. Static export also requires Kaleido and a compatible Chrome or Chromium installation, as described below.

To save an interactive HTML file:

fig.write_html("plot.html")

Open the resulting file in a browser to interact with the chart. For details about HTML export options, refer to Plotly’s interactive HTML export guide.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Export a static image when interactivity is not needed

Plotly’s current static export documentation requires Kaleido version 1.0.0 or later. Kaleido v1 expects Chrome or Chromium to be installed and available. Plotly documents two installation routes for Chrome: the plotly_get_chrome command-line utility and plotly.io.get_chrome() in Python.

pip install --upgrade kaleido
plotly_get_chrome

Alternatively, use the documented Python route:

import plotly.io as pio

pio.get_chrome()

Once the required setup is in place, write an image in a supported format:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
fig.write_image("plot.png")

The documented formats include PNG, JPEG, WebP, SVG, and PDF. For example, change the filename extension to .svg or .pdf to request those formats. Vector formats can be useful for scalable figures, but Plotly notes that rendering very large plots fully as vectors can be slow. Operating system, package versions, and browser availability can affect setup, so consult the current static image export documentation if installation or export fails.

Quick decision guide

  • For a conventional chart, begin with Plotly Express and customize its returned figure as needed.
  • For direct trace and layout control or specialized subplot construction, use graph objects.
  • To view a chart in your current Python environment, call fig.show().
  • To share a browser-openable interactive artifact, use fig.write_html("plot.html").
  • To place a non-interactive chart in a static document, export an image and confirm Kaleido and Chrome or Chromium are available.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.