Scatter Plot in Plotly
Last Updated: 08 Nov 2025
Scatter plots show individual data points as markers — perfect for correlation, clustering, outliers, or 2D relationships.
Hinglish Tip: Scatter plot = "har point ko alag dikhana" — jaise stars in the sky. No line, just dots with meaning.
Basic Scatter Plot
import plotly.express as px
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 15, 13, 18, 22]
fig = px.scatter(x=x, y=y, title="Basic Scatter")
fig.show()
Key Parameters in px.scatter()
Full Featured Example
import plotly.express as px
import pandas as pd
# Sample dataset
df = pd.DataFrame({
'City': ['Delhi', 'Mumbai', 'Bangalore', 'Chennai', 'Kolkata'],
'Temperature': [32, 30, 28, 35, 29],
'Humidity': [60, 80, 70, 75, 85],
'Pollution': [120, 95, 80, 110, 130],
'Region': ['North', 'West', 'South', 'South', 'East']
})
fig = px.scatter(
df,
x='Temperature',
y='Humidity',
size='Pollution',
color='Region',
hover_name='City',
hover_data={'Pollution': True, 'Temperature': False},
symbol='Region',
title='City Climate Analysis: Temp vs Humidity',
labels={
'Temperature': 'Temp (°C)',
'Humidity': 'Humidity (%)',
'Pollution': 'AQI Level'
},
width=900,
height=600
)
fig.update_layout(
legend_title="Region",
font=dict(size=12)
)
fig.show()
Hinglish Tip: size='Pollution' → bada bubble = zyada pollution — ek nazar mein samajh aayega!
Add Trendline (Regression)
fig = px.scatter(df, x='Temperature', y='Humidity', trendline="ols", title="With Trendline")
fig.show()
Options: "ols", "lowess", "rolling", "expanding"
