# Plotly Tutorial: A Guide to Interactive Charts in Python

> A Plotly tutorial for Python covering Plotly Express chart types, hover tooltips, legends, subplots, templates, exporting figures and building a Dash app.

Source: https://www.pythoncharts.com/plotly/plotly-tutorial/ | Published: 2026-11-27 | Author: Alex Scott | Category: Plotly | Tags: plotly, plotly express, guide, interactive charts, dashboard

To make an interactive chart with Plotly, call a Plotly Express function such as `px.line()` or `px.bar()` on a DataFrame, then `fig.show()`. The result has hover tooltips and zoom without extra code. These tutorials are grouped by task, and newer ones are written for Plotly 6.

![Grid of twelve Plotly charts: line, bar, box, heatmap, subplots, 3D, Sankey, treemap, sunburst, candlestick, map and funnel charts](https://www.pythoncharts.com/plotly/plotly-tutorial/images/plotly-tutorial-montage.png)

## Quick Example

```python
import pandas as pd
import plotly.express as px

df = pd.DataFrame({
    "quarter": ["Q1", "Q2", "Q3", "Q4"] * 2,
    "region": ["North"] * 4 + ["South"] * 4,
    "revenue": [210, 245, 238, 290, 180, 198, 231, 262],
})

fig = px.bar(df, x="quarter", y="revenue", color="region",
             barmode="group", title="Revenue by Region",
             labels={"revenue": "Revenue ($k)", "quarter": ""})
fig.show()
```

![Grouped bar chart in which the North region's quarterly revenue is above the South region's in all four quarters](https://www.pythoncharts.com/plotly/plotly-tutorial/images/plotly-tutorial-quick-example.png)

## Where Should I Start With Plotly?

| Step | Question | Tutorial |
|---|---|---|
| 1. First chart | How do I draw lines from a DataFrame? | [Line charts](https://www.pythoncharts.com/plotly/plotly-express-line-charts/) |
| 2. Compare | How do I group or stack bars? | [Bar charts](https://www.pythoncharts.com/plotly/plotly-express-bar-charts/) |
| 3. Label it | How do I set titles and font sizes? | [Font size and titles](https://www.pythoncharts.com/plotly/plotly-font-size-titles/) |
| 4. Inspect | How do I control what hover shows? | [Hover tooltips](https://www.pythoncharts.com/plotly/plotly-customize-hover-tooltips/) |
| 5. Share | How do I send someone the chart? | [Standalone HTML](https://www.pythoncharts.com/plotly/plotly-saving-standalone-html-files/) |

If `fig.show()` displays nothing, start with [renderers](https://www.pythoncharts.com/plotly/plotly-not-showing-renderers/).

## Which Plotly Chart Should I Use?

To choose by appearance, browse the [Python Chart Gallery](https://www.pythoncharts.com/chart-gallery/).

| To show | Function | Tutorial |
|---|---|---|
| A trend over time | `px.line` | [Line charts](https://www.pythoncharts.com/plotly/plotly-express-line-charts/) |
| Values by category | `px.bar` | [Bar charts](https://www.pythoncharts.com/plotly/plotly-express-bar-charts/) |
| One distribution | `px.histogram` | [Histograms](https://www.pythoncharts.com/plotly/plotly-histograms/) |
| Distributions by group | `px.box`, `px.violin` | [Box and violin plots](https://www.pythoncharts.com/plotly/plotly-box-violin-plots/) |
| A grid of values | `px.imshow` | [Heatmaps](https://www.pythoncharts.com/plotly/plotly-heatmaps/) |
| Parts of a whole | `px.pie` | [Pie and donut charts](https://www.pythoncharts.com/plotly/plotly-pie-charts-donut-charts/) |
| A hierarchy as rectangles | `px.treemap` | [Treemaps](https://www.pythoncharts.com/plotly/treemap-hierarchical-colors/) |
| A hierarchy as rings | `px.sunburst` | [Sunburst charts](https://www.pythoncharts.com/plotly/interactive-sunburst-charts/) |
| Flows between stages | `go.Sankey` | [Sankey diagrams](https://www.pythoncharts.com/plotly/plotly-sankey-diagram/) |
| Drop-off between steps | `px.funnel` | [Funnel charts](https://www.pythoncharts.com/plotly/plotly-funnel-charts/) |
| A schedule | `px.timeline` | [Gantt charts](https://www.pythoncharts.com/plotly/gantt-charts/) |
| Stock prices | `go.Candlestick` | [Candlestick charts](https://www.pythoncharts.com/plotly/interactive-candlestick-charts/) |
| Places | `px.scatter_geo`, `px.choropleth` | [Maps](https://www.pythoncharts.com/plotly/plotly-geo-maps/) |
| Three dimensions | `px.scatter_3d`, `go.Surface` | [3D plots](https://www.pythoncharts.com/plotly/plotly-3d-plots/) |
| Several measures per item | `go.Scatterpolar` | [Radar charts](https://www.pythoncharts.com/plotly/radar-spider-charts-plotly/) |
| Many numeric columns | `px.parallel_coordinates` | [Parallel coordinates](https://www.pythoncharts.com/plotly/parallel-coordinates-plot/) |
| Change over time as motion | `animation_frame=` | [Animated bubble charts](https://www.pythoncharts.com/plotly/animated-bubble-charts/) |
| A single headline number | `go.Indicator` | [Gauges and KPI cards](https://www.pythoncharts.com/plotly/plotly-gauge-indicator-charts/) |

## Layout, Legends, and Axes

| You want to | Tutorial |
|---|---|
| Set width, height and margins | [Figure size and margins](https://www.pythoncharts.com/plotly/plotly-figure-size-margins/) |
| Move the legend | [Legend position](https://www.pythoncharts.com/plotly/plotly-legend-position/) |
| Change background colors | [Plot and paper background](https://www.pythoncharts.com/plotly/plotly-background-color-plot-vs-paper/) |
| Apply a theme or build your own | [Templates and themes](https://www.pythoncharts.com/plotly/plotly-templates-themes/) |
| Format dollars or percentages | [Axis number formats](https://www.pythoncharts.com/plotly/plotly-format-axes-percentages-currency/) |
| Rotate tick labels | [Rotate tick labels](https://www.pythoncharts.com/plotly/plotly-rotate-tick-labels-plotly-express/) |
| Add reference lines | [Horizontal and vertical lines](https://www.pythoncharts.com/plotly/plotly-add-horizontal-vertical-lines/) |
| Add notes and arrows | [Annotations](https://www.pythoncharts.com/plotly/plotly-add-custom-annotations/) |

## Subplots

| You want to | Tutorial |
|---|---|
| Combine charts or add a second y-axis | [make_subplots](https://www.pythoncharts.com/plotly/plotly-make-subplots/) |
| Keep panels in proportion | [Fixed aspect ratios](https://www.pythoncharts.com/plotly/plotly-fixed-aspect-ratios-subplots/) |

## Interactivity and Performance

| You want to | Tutorial |
|---|---|
| Switch data from a menu or button | [Dropdowns and buttons](https://www.pythoncharts.com/plotly/plotly-dropdown-menus-buttons/) |
| Scrub through a long time series | [Range sliders and selectors](https://www.pythoncharts.com/plotly/range-slider-selector-time-series/) |
| Hide the toolbar | [Remove the modebar](https://www.pythoncharts.com/plotly/plotly-remove-modebar/) |
| Lock zoom on one axis | [Disable zooming or panning](https://www.pythoncharts.com/plotly/plotly-disable-zooming-panning-specific-axes/) |
| Draw many points smoothly | [WebGL performance](https://www.pythoncharts.com/plotly/plotly-webgl-performance/) |
| Connect charts to Python callbacks | [Dash tutorial](https://www.pythoncharts.com/plotly/dash-tutorial-python-dashboard/) |

## Export Plotly Charts

| You need | Method | Tutorial |
|---|---|---|
| An interactive file | `fig.write_html()` | [Standalone HTML](https://www.pythoncharts.com/plotly/plotly-saving-standalone-html-files/) |
| A chart inside your own web page | `fig.to_html(full_html=False)` | [Embed charts in a website](https://www.pythoncharts.com/python/embed-interactive-charts-website/) |
| A PNG, SVG or PDF | `fig.write_image()` with Kaleido | [Static image export](https://www.pythoncharts.com/plotly/plotly-export-static-images-with-kaleido/) |

## Should I Use Plotly Express or Graph Objects?

| Choose | When |
|---|---|
| `plotly.express` (`px`) | You have a DataFrame and want one function per chart |
| `plotly.graph_objects` (`go`) | You are assembling traces yourself or need a chart `px` lacks, such as `go.Sankey` |
| `make_subplots` | Several chart types have to share one figure |
| [Dash](https://www.pythoncharts.com/plotly/dash-tutorial-python-dashboard/) | Inputs need to rerun Python code |

A Plotly Express call returns a graph objects `Figure`, so you can start with `px` and refine it with `fig.update_layout()` and `fig.update_traces()`.

## Common Plotly Problems

| Problem | Fix | Details |
|---|---|---|
| The chart doesn't appear | Check the renderer and that `nbformat` is installed | [Renderers](https://www.pythoncharts.com/plotly/plotly-not-showing-renderers/) |
| A line zigzags back and forth | Sort the data by the x column | [Line charts](https://www.pythoncharts.com/plotly/plotly-express-line-charts/) |
| `write_image()` fails | Install Kaleido and the browser it needs | [Kaleido](https://www.pythoncharts.com/plotly/plotly-export-static-images-with-kaleido/) |
| Long labels are cut off | Increase the margin or turn on `automargin` | [Size and margins](https://www.pythoncharts.com/plotly/plotly-figure-size-margins/) |
| Large scatter plots lag | Use `render_mode="webgl"` or `go.Scattergl` | [WebGL](https://www.pythoncharts.com/plotly/plotly-webgl-performance/) |

## Similar Topics

- [Matplotlib Tutorial: from first plot to polished chart](https://www.pythoncharts.com/matplotlib/matplotlib-tutorial/)
- [Seaborn Tutorial: statistical charts from DataFrames](https://www.pythoncharts.com/seaborn/seaborn-tutorial/)
- [Python Interactive Charting Libraries Compared](https://www.pythoncharts.com/python/python-interactive-charting-libraries-compared/)
