Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 31 ยท Getting Started

Interactive Data Visualization: The Big Picture

Learn what interactive charts are, how Plotly, Bokeh and Altair differ, how they render in a browser, and how to choose a library for your project.

A chart is a picture of numbers that lets your eyes do the comparing. A static chart, like a PNG exported from a plotting library, shows one view and nothing more. An interactive chart lets the reader hover for exact values, zoom into a crowded region, click a legend entry to hide a series, or drag a slider and watch the picture change. Interactivity turns a chart from an answer into a tool for asking questions.

This tutorial covers three Python libraries that produce interactive charts for the web: Plotly, Bokeh and Altair. They look different in code but share one big idea: you describe a chart as data, and a JavaScript engine in the browser draws it. Once you see that, switching between the libraries becomes much easier. If you want static, publication-style figures first, start with the Matplotlib tutorial; you do not need it here.

Static versus interactive

A static chart is rendered once, on the computer that made it, into pixels (PNG) or vector shapes (SVG, PDF). It never changes, which is a strength: it prints well, it looks the same everywhere, and it needs no code to view.

An interactive chart ships data plus drawing instructions to the browser, and the browser keeps the chart alive. When the mouse moves, a script finds the nearest data point and shows a tooltip. When you drag a box, the script rescales the axes and redraws. The price is a larger page, a JavaScript runtime on the reader's side, and more things that can go wrong.

Static chart Interactive chart
Output Image or PDF HTML page with data and script
Exact values Only if labeled Hover tooltips
Large data Fine (it is just pixels) Can get slow in the browser
Print and slides Excellent Needs a screenshot
Exploring data One fixed view Zoom, filter, link views

Neither kind is better; pick the one that fits where the chart will be read. A figure in a printed report wants a static image. A dashboard that people poke at wants interaction.

The three libraries in one paragraph each

Plotly (plotly) is the most widely used. Its high-level interface, Plotly Express, builds a whole chart in one line, such as px.scatter(df, x="price", y="rating"). Under the hood, every figure is a plain dictionary of data (a list of traces) and layout, which is drawn by the JavaScript library Plotly.js. Plotly also has Dash, a framework for building web dashboards in pure Python.

Bokeh (bokeh) is lower level and very flexible. You create a figure, add glyphs (circles, lines, bars) that read from a ColumnDataSource, and attach tools and widgets. Bokeh's own JavaScript library, BokehJS, draws the result. Bokeh can also run a server so Python code reacts to user actions and streams live data.

Altair (altair) is declarative. You say what you want, not how to draw it: "bars, with month on the x axis and the sum of units on the y axis". Altair writes a Vega-Lite specification, a JSON document that the Vega-Lite JavaScript library turns into a chart. Its compact style is a good match for exploratory analysis in notebooks.

How a chart gets into the browser

All three follow the same path from your Python data to pixels.

flowchart LR
    A["Your data<br/>(DataFrame)"] --> B["Python library<br/>builds a description"]
    B --> C["JSON document<br/>(figure, model or spec)"]
    C --> D["HTML page<br/>+ JavaScript engine"]
    D --> E["SVG or canvas<br/>in the browser"]
    E --> F["Mouse and keyboard<br/>events"]
    F --> D

Python only builds the description. The browser engine draws it and handles every interaction after that.

This has practical consequences you will meet again and again:

  • A saved chart is an HTML file with embedded JSON. You can email it or host it as a static page.
  • A chart is only as interactive as its JavaScript. Without a server, interactions that need Python (such as recomputing a model on a slider move) are not possible.
  • The data you chart is copied into the page. A million points means a heavy page. We deal with this in Large Datasets and Performance.
  • Because the description is plain data, you can test it, diff it and generate it from other languages.

What runs here, and what does not

Be clear about the limits of this site. Plotly, Bokeh and Altair need a Python environment with the packages installed, and their charts need their JavaScript engines. The in-browser runners here cannot install and run them. So in this tutorial:

  • Code that uses the real libraries appears in read-only code blocks. It is correct for current versions, but you run it on your own computer.
  • Next to each, you get runnable stand-ins in the editors: small programs that do by hand what the library does inside, such as turning a table into a figure dictionary, computing quartiles, or mapping a mouse position to a data point. Each lesson says which part is real and which part is the stand-in.

The stand-ins are not busywork. A chart library is a pile of small, understandable ideas, and building a toy version is the quickest way to learn them.

A first stand-in: an interactive chart, reduced to its core. Four bars share a 400-pixel width, so each month owns a 100-pixel band. A mouse position is mapped to a band, and the band to a row of data.

JS Tooltip lookup: from mouse position to data row

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

No output.

A real library does the same job with more care (pixel scales, nearest point in two dimensions, many trace types), but a hover tooltip is exactly this: a function from pixels back to data. Notice the clamp with Math.min and Math.max: a mouse outside the plot still gives a valid row.

Same chart, three descriptions

The three libraries describe the same bar chart in different shapes. Here is the real Plotly Express call, as read-only code:

Python
import plotly.express as px

fig = px.bar(df, x="month", y="units", title="Units per month")
fig.show()

The Altair version of the same chart:

Python
import altair as alt

chart = alt.Chart(df).mark_bar().encode(x="month", y="units")
chart.show()

And Bokeh, which spells out more steps:

Python
from bokeh.plotting import figure, show

p = figure(x_range=list(df["month"]), title="Units per month")
p.vbar(x=df["month"], top=df["units"], width=0.8)
show(p)

The next stand-in builds simplified descriptions of that chart in the three styles and prints their shape. The real documents contain more fields (Plotly adds default layout details, Bokeh serializes a whole object graph, Altair adds a schema URL), so treat these as sketches that keep the essential structure.

JS One bar chart, three kinds of description

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

No output.

Look at what differs. Plotly separates traces (the data being drawn) from layout (everything around them). Bokeh separates the source (columns of data) from the glyph (the shape that reads them), so many glyphs and widgets can share one table. Vega-Lite puts the rows inside the spec and describes the chart through encodings: which field goes to which visual channel, and what kind of data it is. These three choices shape how each library feels to use.

Choosing a library

There is no winner, only trade-offs. These rules of thumb hold up well:

  • Quick, good-looking charts and dashboards: Plotly Express, with Dash if you need an app. Great defaults, a huge chart gallery, and the same figures work in Python, R and JavaScript.
  • Custom interactivity and live data: Bokeh. Its tools, widgets, linked views and server make it strong for monitoring screens and streaming data.
  • Exploring data with little code: Altair. A small set of building blocks (marks, encodings, transforms, selections) combines in a very regular way. It embeds the data in the spec, so it suits modest data sizes best.
  • Print and papers: Matplotlib, not these three.

You can also mix them: many teams explore in Altair, publish in Plotly and keep one Bokeh dashboard for streaming. The skills transfer, especially tidy data and the grammar of how charts work inside.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What do Plotly, Bokeh and Altair actually send to the browser?

    Python builds a description such as a figure, a document model or a Vega-Lite spec. A JavaScript library in the page draws it and handles hover, zoom and clicks.
  2. 2. Which situation favors a static chart over an interactive one?

    Printed and PDF output cannot hover or zoom, and an image is lighter and looks the same everywhere. Interactivity pays off when readers explore on screen.
  3. 3. Which library writes a Vega-Lite specification?

    Altair is a Python interface to Vega-Lite. Its Chart objects turn into Vega-Lite JSON, which the Vega-Lite JavaScript library renders.
  4. 4. Why are the real Plotly, Bokeh and Altair calls shown as read-only code on this site?

    The site's runners cannot install these libraries or host their JavaScript engines, so the lessons pair read-only real code with runnable stand-ins that show the same ideas.

Summary

  • A static chart is a fixed picture; an interactive chart is data plus a script that keeps it alive in the browser.
  • Plotly (figures of traces and layout), Bokeh (glyphs reading a ColumnDataSource) and Altair (declarative Vega-Lite specs) all build a JSON description that JavaScript draws.
  • Saved charts are HTML files, interactions that need Python need a server, and charted data is copied into the page.
  • Real library code here is read-only; the TryIt stand-ins show the same ideas working by hand.
  • Choose Plotly for fast dashboards, Bokeh for custom and live interaction, Altair for compact exploration.

Next: How a Chart Works Inside.