Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 42 ยท Getting Started

What Is Plotly?

Meet Plotly: the library that turns data into interactive charts. Learn how plotly.py, plotly.js, Express and Dash fit together, how to install it and how a figure works.

Plotly is a charting library that produces interactive graphics: hover for exact values, zoom into a region, click a legend entry to hide a series, drag to pan. Instead of a static picture, you get a small web application that runs in the browser. Plotly charts are used in notebooks, dashboards, reports and web apps, and the same chart can be written in Python, R, JavaScript and Julia.

In this course you use the Python library, called plotly.py. You will learn the quick one-line interface (Plotly Express), the detailed interface (graph objects), how to style every part of a chart and how to put charts into Dash apps. If you already know pandas and Matplotlib, you will feel at home quickly.

The pieces of the Plotly family

"Plotly" is really several projects that work together:

Piece What it is
plotly.js The JavaScript engine that draws charts in the browser (SVG and WebGL). Everything you see is drawn by it.
plotly.py The Python package. It builds a description of a chart and hands it to plotly.js.
Plotly Express (plotly.express) A high-level module inside plotly.py. One function call makes a complete chart from a DataFrame.
Graph objects (plotly.graph_objects) The low-level module. You build traces and layout by hand, with full control.
Dash A framework that turns plotly figures plus widgets into web apps, written in pure Python.

Your Python code never draws pixels. It creates a figure, a nested dictionary of settings, and plotly.js turns that dictionary into a chart in the browser.

flowchart LR
    A["Your data<br/>(DataFrame, lists)"] --> B["plotly.py<br/>px / go"]
    B --> C["Figure<br/>(JSON: data + layout)"]
    C --> D["plotly.js<br/>in the browser"]
    D --> E["Interactive chart"]

Python builds the JSON description; plotly.js draws it.

Install Plotly

On your own computer you install plotly with pip. Pandas is needed for most Express examples, and nbformat is needed to display charts inside Jupyter:

Terminal
pip install plotly pandas nbformat

Check the version in Python:

Python
import plotly
print(plotly.__version__)

On this site you do not install anything locally. The Python runner starts with a fresh Python in your browser, and the first line of each example installs Plotly with micropip:

Python
import micropip
await micropip.install("plotly")

The runner can build figures and show you every number and setting inside them, but it has no screen to draw them on. To see the drawn result we use the live HTML editor, which loads plotly.js directly. Both tools use the same figure format, so what you learn transfers one-to-one.

Your first figure, in the browser

This example uses plotly.js directly. Notice the two arguments: a list of traces (the data) and a layout (title, axes, size). Hover over the points, drag to zoom, double-click to reset.

A first Plotly chart (plotly.js)

That is the whole idea: data is a list of traces, layout is an object. Python gives you friendlier ways to produce exactly this structure.

Your first figure, in Python

Here is the same chart built with plotly.py. We do not draw it; we ask the figure to show its own structure with to_dict().

Python The same chart as a Python figure

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output shows two top-level keys, data and layout. The trace has type: scatter, and the shortcut yaxis_title="visitors" was expanded into the full nested path layout.yaxis.title.text. Python is a convenient way to write the JSON, with autocomplete and error checking added.

Figures are validated

Plotly checks every property you set. A typo raises an error immediately, which is much friendlier than a chart that silently ignores a setting:

Python Plotly rejects bad settings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both calls fail with a ValueError that names the problem. The first names the unknown property and lists the valid ones; the second says the value is not a valid color. This is one of the best reasons to prefer plotly.py over writing JSON by hand.

When to choose Plotly

  • You want interactivity without writing JavaScript.
  • You want charts you can embed in a web page, a dashboard or an email-sized HTML file.
  • You need statistical, scientific, financial, 3D or map charts in the same library.
  • You work in notebooks, Streamlit, Dash or any web framework.

Choose Matplotlib when you need print-quality static figures or very fine control of a publication layout, and Seaborn when you want quick statistical plots with Matplotlib styling. Plotly's strength is exploring data on screen.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which part of the Plotly family actually draws the chart in the browser?

    plotly.py only builds a JSON description of the figure. plotly.js, the JavaScript engine, renders it.
  2. 2. What are the two main parts of every Plotly figure?

    A figure holds a list of traces in data and everything else (title, axes, size, legend) in layout.
  3. 3. What is the difference between Plotly Express and graph objects?

    Both produce the same figure type. Express builds a whole chart from a DataFrame in one call, and graph objects let you assemble traces and layout yourself.
  4. 4. What happens if you pass an unknown property such as titel to update_layout?

    Figures are validated, so typos fail loudly with a helpful message.

Summary

  • Plotly makes interactive charts; plotly.py builds a figure and plotly.js draws it.
  • A figure is JSON-like: data (a list of traces) plus layout.
  • Plotly Express is the quick interface, graph objects the detailed one, Dash adds widgets and web apps.
  • Install with pip install plotly; on this site, micropip does it inside the page.
  • Plotly validates every setting, so mistakes show up as clear errors.

Next: Plotly Express Basics