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()

ParameterValues / ShorthandPurpose
data_framedf (Pandas DataFrame)Use real dataset
x, yColumn names or listsX and Y axis data
colorColumn name or listColor by category
sizeColumn nameBubble size
hover_nameColumnLabel on hover
hover_dataList of columnsExtra info on hover
symbolColumn or marker typeDifferent shapes
titleStringPlot title
labelsDict: 'col': 'New Name'Rename axes
width, heightPixels (e.g. 800)Figure size

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"


Common Mistakes to Avoid

MistakeFix
No hover infoUse hover_name + hover_data
Too many points → slowUse render_mode='webgl' for 100k+ points
Default colors hard to readUse color_discrete_sequence=px.colors.qualitative.Bold
Can't exportInstall kaleido: pip install kaleido
Small plotSet width=900, height=600