You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Plotly is a Python library for creating interactive, publication-quality visualisations that can be displayed in Jupyter notebooks, embedded in web applications, or exported as standalone HTML files. Unlike Matplotlib and Seaborn (which produce static images), Plotly charts support hover tooltips, zoom, pan, click events, and animations out of the box.
pip install plotly
Plotly has two main APIs:
| API | Description | Code Complexity |
|---|---|---|
Plotly Express (px) | High-level, concise, DataFrame-friendly | Low |
Graph Objects (go) | Low-level, maximum customisation | Higher |
Tip: Start with Plotly Express for most charts. Drop down to Graph Objects only when you need advanced customisation.
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length",
color="species", size="petal_length",
hover_data=["petal_width"],
title="Iris Dataset — Sepal Dimensions")
fig.show()
import plotly.express as px
df = px.data.gapminder()
df_uk = df[df["country"] == "United Kingdom"]
fig = px.line(df_uk, x="year", y="gdpPercap",
title="UK GDP Per Capita Over Time",
labels={"gdpPercap": "GDP Per Capita (USD)",
"year": "Year"})
fig.show()
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.