import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv")
print(df.shape)
df.head()
(150, 5)
sepal_length | sepal_width | petal_length | petal_width | species | |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
p = ggplot(df) + geom_point(aes('petal_length', 'petal_width', color='species'), size=5) + ggsize(600, 400)
p
fullpath_svg = ggsave(p, "plot.svg")
Load and display saved SVG.
from IPython.display import SVG
display(SVG(filename=fullpath_svg))
By default, when exporting HTML, ggsave
wraps the HTML of the plot in an iframe
that matches the size of the plot.
fullpath_html = ggsave(p, "plot.html")
Load and display saved HTML.
from IPython.display import HTML
display(HTML(filename=fullpath_html))
Use the iframe=False
option to only export the HTML of the plot, without adding an iframe
.
fullpath_no_iframe = ggsave(p, "no_iframe_plot.html", iframe=False)
display(HTML(filename=fullpath_no_iframe))
fullpath_png = ggsave(p, "plot.png")
Load and display saved PNG.
from IPython.display import Image
display(Image(filename=fullpath_png, width=600, height=400))
!rm -rf lets-plot-images