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.
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
From gallery to your data
In the appOpen 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.
What does the Code tab give you?
PredictPredict first
You open the Code tab on a tuned histogram. What do you get?
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.
Three dialects
ReadHere is a histogram in two of them. The Charts page writes the equivalent for your data and settings.
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()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.
Check the other tabs
ExploreEach 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?
Send it onward
ReadThe 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.
Check your understanding
CheckpointCheck 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.
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