Visualization Samples by Plotly Express
Goal¶
This post aims to introduce examples of visualization by Plotly Express.
The followings are introduced:
- Prepared example data
- Scatter plot
- basic
- basic + size
- basic + size + color
- basic + size + color + time
- heatmap + histogram
Reference
Libraries¶
In [8]:
import pandas as pd
import numpy as np
import plotly_express as px
import plotly.io as pio
pio.renderers.default = "png"
Load a prepared data¶
Car Share¶
In [2]:
df = px.data.carshare()
df.head()
Out[2]:
Tips¶
In [3]:
df = px.data.tips()
df.head()
Out[3]:
Election¶
In [4]:
df = px.data.election()
df.head()
Out[4]:
Wind¶
In [5]:
df = px.data.wind()
df.head()
Out[5]:
Gap Minder¶
In [6]:
df = px.data.gapminder()
df.head()
Out[6]:
Scatter Plot¶
Basic Scatter plot¶
In [10]:
px.scatter(df, x='gdpPercap', y='lifeExp', width=900, height=400)
Scatter plot + size¶
In [11]:
px.scatter(df, x='gdpPercap', y='lifeExp', size='pop', width=900, height=400)
Scatter plot + size + color¶
In [12]:
px.scatter(df, x='gdpPercap', y='lifeExp', size='pop', color='country', width=900, height=400)
Scatter plot + size + color + time¶
In [13]:
px.scatter(df, x='gdpPercap', y='lifeExp', size='pop', color='country', animation_frame='year', width=900, height=400)
In [14]:
px.density_heatmap(df, x="gdpPercap", y="lifeExp", marginal_y="histogram", marginal_x="histogram")
Comments
Comments powered by Disqus