Plotly — Interactive Charts in Python That You Can Zoom, Hover, and Explore
After learning Matplotlib and Seaborn, I thought I had a solid grip on data visualization. Both are great tools. But there was one thing they could not do — make charts interactive.
Then I learned Plotly. And it completely changed how I think about visualization.
In this post I will share everything I learned about Plotly — both Plotly Express and Plotly Graph Objects — and when to use which. This is Blog 4 in my Data Science journey series.
What is Plotly?
Plotly is a Python visualization library that creates fully interactive charts. Every chart you make with Plotly lets you hover over data points to see exact values, zoom into specific regions, pan across the chart, click to hide or show specific data, and download the chart as an image — all without writing a single extra line of code.
This is the key difference from Matplotlib and Seaborn. Those libraries produce static images. Plotly produces living, interactive charts that work in Jupyter notebooks, web browsers, and dashboards.
💡 Plotly is the go-to library when you want to share charts with others or build dashboards — because the person reading your chart can explore it themselves instead of just looking at a picture.
Plotly Express vs Plotly Graph Objects
This is the first thing you need to understand about Plotly. It has two interfaces and knowing which one to use will save you a lot of confusion.
Plotly Express (px) — The high-level, beginner-friendly interface. It works directly with Pandas DataFrames and can create most chart types in a single line of code. Perfect for quick exploration and EDA.
Plotly Graph Objects (go) — The low-level interface that gives you full control over every element of a chart. More code, but unlimited customization. This is what you use for complex layouts, mixed chart types, and dashboards.
| Plotly Express | Graph Objects | |
|---|---|---|
| Speed | One-liner charts | Verbose but full control |
| Input | Pandas DataFrames | Arrays, dicts, traces |
| Customization | Limited | Unlimited |
| Best For | EDA, quick charts | Dashboards, complex layouts |
| Subplots | Limited support | Full via make_subplots |
| Mixing chart types | Not directly | Yes — fig.add_trace() |
My rule of thumb — start with px for speed, switch to go when you need precise control or want to mix different chart types in one figure.
Plotly Express — All the Charts I Learned
Line and Scatter Charts
The line chart in Plotly Express is as simple as it gets — one line of code, and you get an interactive chart with hover tooltips built in.
import plotly.express as px
fig = px.line(df, x='date', y='price', title='Stock Price Over Time')
fig.show()
Scatter plots work the same way. The real power comes from parameters like color, size, and hover_data — you can encode multiple dimensions into a single interactive scatter plot and the user can explore each point by hovering.
Bar Charts
Plotly's bar charts support vertical bars, horizontal bars, grouped bars, and stacked bars — all interactive. The color parameter lets you split bars by category automatically.
fig = px.bar(df, x='team', y='runs', color='season', barmode='group')
fig.show()
Histogram
The Plotly histogram is interactive — you can hover over each bin to see the exact count. You can overlay multiple histograms using color= and control whether they are stacked, overlaid, or shown side by side using barmode=.
Pie and Donut Charts
Pie charts in Plotly are interactive — hover over each slice to see the label and percentage. A donut chart is just a pie chart with a hole in the center, achieved with the hole= parameter.
fig = px.pie(df, names='category', values='count', hole=0.4)
fig.show()
Box and Violin Charts
These work exactly as you would expect from Seaborn — but now they are interactive. Hover over the box to see quartile values, or hover over individual points to see outlier details.
Area Charts
Area charts are great for showing cumulative trends over time. Plotly's px.area() fills the area under the line and supports stacking multiple series.
Sunburst and Treemap
These are hierarchical visualization charts — they show data organized in nested levels. I used them to visualize IPL data broken down by season, then team, then player.
Sunburst — Circular hierarchical chart where each ring represents a level of the hierarchy.
Treemap — Rectangular hierarchical chart where the size of each rectangle represents a value.
fig = px.sunburst(df, path=['season', 'team', 'player'], values='runs')
fig.show()
Funnel Charts
Funnel charts show how data reduces across stages — like how many users visited a page, then signed up, then purchased. Perfect for conversion analysis.
Choropleth Maps
This was one of the most impressive things I learned. A choropleth map colors countries or regions based on a data value — like a world map where each country is shaded based on GDP, population, or any metric.
fig = px.choropleth(df, locations='country', color='gdp',
color_continuous_scale='Viridis')
fig.show()
3D Charts
Plotly makes 3D charts interactive — you can rotate, zoom, and pan in all three dimensions directly in the browser. I learned 3D scatter plots and 3D line plots using px.scatter_3d() and px.line_3d().
Animations
This was genuinely impressive. You can add a animation_frame= parameter to create an animated chart that plays through a time dimension. I used it to animate how IPL team rankings changed across seasons — it looked like something from a professional sports broadcast.
fig = px.bar(df, x='team', y='runs', animation_frame='season',
range_y=[0, 250])
fig.show()
Plotly Graph Objects — Full Control
While Plotly Express is great for quick charts, Graph Objects is where you build production-quality, complex visualizations.
How it works
Instead of passing a DataFrame directly, you create individual trace objects and add them to a figure manually.
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y, mode='lines+markers', name='Sales'))
fig.update_layout(title='Sales Over Time', xaxis_title='Month')
fig.show()
Charts available in Graph Objects
Everything from Plotly Express is also available in Graph Objects — scatter, bar, pie, histogram, box, violin. But Graph Objects also gives you access to:
Heatmap — go.Heatmap() for grid-based intensity visualization. I used it to plot correlation matrices with full control over colorscale and annotations.
Surface Plot — go.Surface() creates a stunning 3D surface chart. Combined with the viridis colormap, this is one of the most visually impressive charts you can make in Python.
Candlestick Chart — go.Candlestick() is specifically designed for financial data — it shows the open, high, low, and close prices for each time period. This is the standard chart used in stock market analysis.
fig = go.Figure(go.Candlestick(x=df['date'], open=df['open'],
high=df['high'], low=df['low'],
close=df['close']))
fig.show()
Waterfall Chart — go.Waterfall() shows how an initial value changes through a series of positive and negative contributions. Great for financial breakdowns.
Funnel Chart — go.Funnel() with full control over colors, text, and connector styles.
Subplots with make_subplots
This is where Graph Objects becomes truly powerful. Using make_subplots() you can create a grid of different chart types in a single figure — each subplot can be a completely different type of chart.
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(x=x, y=y1), row=1, col=1)
fig.add_trace(go.Bar(x=categories, y=values), row=1, col=2)
fig.show()
Secondary Y-Axis
When you have two variables with very different scales — like runs (0-200) and economy rate (6-12) — you can plot them on the same chart with two separate Y-axes using secondary_y=True.
Mixed Chart Types
In Graph Objects you can combine completely different chart types in one figure. For example, a bar chart for total runs overlaid with a line chart for average — both in the same interactive plot.
Custom Layouts and Annotations
fig.update_layout() lets you control every aspect of the figure — title, fonts, background color, legend position, margins, and more. You can also add text annotations directly onto the chart to highlight specific data points.
My Honest Experience
When I first ran a Plotly chart in Jupyter, I spent about 10 minutes just zooming in and out and hovering over data points. It felt like a completely different world compared to Matplotlib's static images.
The learning curve for Plotly Express is almost zero — if you know Seaborn, you will feel comfortable with px immediately. Graph Objects takes more time because you are manually building traces and layouts, but the power it gives you is worth it.
One thing I noticed — Plotly charts look professional by default. You do not need to spend time on styling. The default theme is clean and modern, and the interactivity makes even simple charts impressive.
My honest advice — use Plotly Express for all your EDA. Use Graph Objects when you are building something to share, present, or put in a dashboard.
Key Takeaways
Plotly creates fully interactive charts — hover, zoom, pan, and explore are built in by default
Plotly Express is the fast, high-level interface — one line of code for most charts
Plotly Graph Objects is the low-level interface — verbose but gives unlimited control
Use px for EDA and quick charts, use go for dashboards and complex layouts
Unique charts in Plotly — candlestick, waterfall, sunburst, treemap, choropleth maps, animated charts
make_subplots allows mixing completely different chart types in one interactive figure
Plotly charts look professional by default without any extra styling work
What is next in this series?
What is Data Visualization and why it matters
Matplotlib — The foundation of Python plotting
Seaborn — Beautiful charts with less code
Plotly — Interactive charts in Python — you are here
Matplotlib vs Seaborn vs Plotly — Which to use and when?
If this helped you, drop a reaction and follow along — the final comparison post is coming next! 🚀
