Chapter 63: Plot Plotly
1. First — What is “Plot Plotly” actually?
When students, data science beginners, Python learners or web developers in India search or ask for “Plot Plotly” or “Plotly plot”, they almost always mean:
How to create beautiful, interactive charts / graphs / plots using the Plotly library in Python (or sometimes in JavaScript — but 90% of the time it’s the Python version when said this way)
Plotly is not just one function — it is a complete plotting library (like Matplotlib, but much more modern and interactive).
The phrase “Plot Plotly” usually means:
- “How do I make a plot / graph using Plotly?”
- “Show me the basic syntax to create any plot with Plotly”
- “What is the Plotly way of plotting compared to Matplotlib?”
So today I’m giving you the real teacher-style Plotly introduction + plotting lesson — from zero to good understanding.
2. Why Plotly is so popular in 2025–2026 (especially among students & freshers)
- Graphs are interactive by default (hover to see values, zoom, pan, download PNG, click legends to hide/show lines)
- Looks very professional & modern — perfect for projects, reports, portfolios, interviews
- Works in Jupyter Notebook, Google Colab, VS Code, web apps (Dash), static HTML
- Same library works in Python, JavaScript, R, Julia → learn once, use everywhere
- Free for almost everything (open-source + cloud hosting option)
- Much easier to make 3D plots, maps, financial charts, dashboards than Matplotlib
3. Two Main Plotly Modules You Need to Know
There are two common ways people use Plotly in Python:
| Way | Module name | When to use it | Interactive? | Looks like |
|---|---|---|---|---|
| Classic / simple plots | plotly.express (px) | Quick graphs, 90% of student work | Yes | Very clean & modern |
| Full control / advanced | plotly.graph_objects (go) | Custom dashboards, complex charts | Yes | More customizable |
Most beginners start with plotly.express — it is shorter, easier, and beautiful out of the box.
4. Your First Plotly Plot – Hello World Line Chart (Copy-Paste & Run)
Step 1: Install Plotly (do once in terminal / command prompt / Colab)
|
0 1 2 3 4 5 6 |
pip install plotly |
Step 2: Create file plotly-hello.py or paste in Jupyter/Colab:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# Import Plotly Express (the easy way) import plotly.express as px # Our data: hours of the day and temperature °C hours = [0, 3, 6, 9, 12, 15, 18, 21, 24] temperature = [22, 20, 19, 24, 30, 32, 29, 26, 23] # Create the line plot with ONE line of code fig = px.line( x=hours, y=temperature, title="Temperature Over 24 Hours", labels={"x": "Time (hours)", "y": "Temperature (°C)"}, markers=True, # show dots on points template="plotly_dark" # dark modern theme (optional) ) # Make it look nicer fig.update_traces( line=dict(color='red', width=3), marker=dict(size=10, color='yellow', line=dict(width=2, color='black')) ) # Show the interactive graph fig.show() |
What you see when you run it:
- Beautiful interactive line chart
- Red line with yellow dots
- Hover mouse → see exact value
- Zoom, pan, download PNG button (top-right)
- Dark theme (looks very professional)
This is your first real Plotly plot — congratulations! 🎉
5. Step-by-Step: How We Made This Plot (Blackboard Style)
- Importimport plotly.express as px → px = short name for plotly.express (easy mode)
- Data Two lists: x (time), y (temperature)
- One-line plotpx.line(x=…, y=…, title=…, labels=…) → automatically adds axes, title, grid, hover
- Customizefig.update_traces(…) → change line color, thickness, markers
- Showfig.show() → opens interactive graph (in browser or Jupyter)
6. More Very Useful Plotly Examples (Copy-Paste & Try)
A. Bar Chart (Compare Categories)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import plotly.express as px fruits = ['Apple', 'Banana', 'Orange', 'Mango', 'Grapes'] sales = [450, 320, 280, 510, 190] fig = px.bar( x=fruits, y=sales, title="Fruit Sales This Month", labels={"x": "Fruit", "y": "Sales (₹)"}, color=sales, # color bars by value color_continuous_scale='Viridis' ) fig.show() |
B. Scatter Plot (Relationship)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import plotly.express as px hours_studied = [2, 3, 5, 1, 4, 6, 7, 2, 5, 8] marks = [45, 55, 78, 38, 65, 82, 90, 42, 72, 95] fig = px.scatter( x=hours_studied, y=marks, title="Study Hours vs Marks", labels={"x": "Hours Studied", "y": "Marks Obtained"}, trendline="ols", # add trend line (linear regression) hover_name=[f"Student {i+1}" for i in range(len(hours_studied))] ) fig.show() |
C. Pie Chart (Proportions)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import plotly.express as px budget = {'Rent': 12000, 'Food': 8000, 'Transport': 3000, 'Savings': 5000, 'Fun': 2000} fig = px.pie( names=budget.keys(), values=budget.values(), title="Monthly Budget Breakdown", hole=0.4 # makes it donut chart ) fig.show() |
7. Teacher’s Quick Tips (Hyderabad Student Style 😄)
- Start with plotly.express (px) — 90% of student projects need only this
- Always add title and labels — teacher will deduct marks if missing
- Common mistake #1: Forget fig.show() → nothing appears
- Common mistake #2: Run in normal Python file without Jupyter → may not open graph (add fig.write_html(“chart.html”) to save as web page)
- Pro tip: In Jupyter/Colab add import plotly.io as pio; pio.renderers.default = ‘browser’ → opens in new tab
- Pro tip 2: Save for report: fig.write_image(“chart.png”, scale=3) → high quality PNG
Understood what Plotly plotting is now? Plotly is currently one of the best & most impressive plotting tools students can learn — interactive, beautiful, easy, and looks very professional in projects & interviews.
Tell me honestly — what do you want next?
- Bar chart with custom colors + hover info?
- 3D scatter plot?
- Interactive dashboard with multiple plots?
- How to make Plotly work in HTML file (no Python server)?
- Or 20-question Plotly quiz?
Just say — we can build any Plotly chart together step by step! 🚀
