Scatter-Plot-Plotly
Sat 17 May 2025
title: "Scatter Plot - Plotly" author: "Rj" date: 2020-09-05 description: "Simple Plot on Plotly" type: technical_note draft: false
# x and y given as array_like objects
import plotly.express as px
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.show()
x = ['Maths', 'Science']
y = [1, 10]
fig = px.scatter(x= x, y=y)
fig.show()
df = px.data.iris() # iris is a pandas DataFrame
df.head()
| sepal_length | sepal_width | petal_length | petal_width | species | species_id | |
|---|---|---|---|---|---|---|
| 0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa | 1 |
| 1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa | 1 |
| 2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa | 1 |
| 3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa | 1 |
| 4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa | 1 |
fig = px.scatter(df, x="sepal_width", y="sepal_length")
fig.show()
import pandas as pd
data = {
'Math' : [98, 95, 97, 100],
'Science' : [100, 99, 98, 90]
}
df = pd.DataFrame(data, columns = ['Math', 'Science'])
df
| Math | Science | |
|---|---|---|
| 0 | 98 | 100 |
| 1 | 95 | 99 |
| 2 | 97 | 98 |
| 3 | 100 | 90 |
df.style.background_gradient(cmap='YlGnBu')
| Math | Science | |
|---|---|---|
| 0 | 98 | 100 |
| 1 | 95 | 99 |
| 2 | 97 | 98 |
| 3 | 100 | 90 |
Score: 10
Category: plotly