Skip to content

Exporting to matplotlib, plotly and ggplot2

Tune a chart, bind it to your data, copy its code in three libraries, and export or send it onward.

Applied ~8 min7 steps

You will be able to

  • Bind a recipe to your own data
  • Get the code for a chart in matplotlib, plotly or ggplot2
  • Export an image, or send a chart to a report

Read first

01

From gallery to your data

In the app

Open Charts in the sidebar and choose Histogram. Tune it with the controls, then choose Use my data and pick a numeric column.

The chart now runs on your column, and the Code tab updates to match.

02

What does the Code tab give you?

Predict

Predict first

You open the Code tab on a tuned histogram. What do you get?

A pictureCode that reproduces this chartOnly the settings
Reveal

The answer: Code that reproduces this chart

Code you can run and keep: Python with matplotlib/seaborn or plotly, R with ggplot2, or SQL for the numbers behind it. Your tuned controls come through, so you can carry on from there in a notebook.

03

Three dialects

Read

Here is a histogram in two of them. The Charts page writes the equivalent for your data and settings.

Python
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("airquality.csv")
fig, ax = plt.subplots()
ax.hist(df["Ozone"].dropna(), bins=20)
ax.set_xlabel("Ozone (ppb)")
ax.set_ylabel("Days")
plt.show()
R
library(ggplot2)

df <- read.csv("airquality.csv")
ggplot(df, aes(x = Ozone)) +
  geom_histogram(bins = 20) +
  labs(x = "Ozone (ppb)", y = "Days")

The two languages can place bin edges differently from each other. The Export tab shows how closely a target matches the app's version.

04

Check the other tabs

Explore

Each recipe has the same tabs:

  • How to read explains what to look for.
  • Data shows the numbers behind the marks.
  • Method lists its conventions and references.
  • Code and Export take it out of the app.
  • Tests shows how it is checked.

Open Method on a chart you use often. Is there a convention you didn't know about?

05

Send it onward

Read

The Charts page can copy an SVG, or download an SVG or a PNG. Once a chart is on your data, its send-to menu puts it into a report or a dashboard.

06

Check your understanding

Checkpoint

Check yourself

Why keep a chart's code alongside the image?

Show the answer

Answer: a

An image is a snapshot. Code makes the chart reproducible.

Check yourself

You're adding a chart to a printed report. Which export is the best choice?

Show the answer

Answer: a

Vector images stay sharp at any size. A screenshot or a small PNG will blur in print.

07

Recap

Recap
  • Use my data binds a recipe to your column.
  • The Code tab gives you matplotlib/seaborn, plotly, ggplot2 or SQL.
  • Export an image, or send the chart to a report or dashboard.

Concepts in this lesson