import plotly.express as px
import numpy as np
import pandas as pd
28 Plotly
The very basics of plotly
28.1 Boxplot
= np.random.randn(300)
x = np.random.randn(400) + 1.6
y = np.random.randn(320) - 2.2 z
=x) px.box(y
= pd.DataFrame({
dat "key": ["x"]* 300 + ["y"] * 400 + ["z"] * 320,
"val": np.concatenate((x, y, z))
}) dat.head()
key | val | |
---|---|---|
0 | x | -0.719056 |
1 | x | -1.598678 |
2 | x | 0.265365 |
3 | x | 1.219989 |
4 | x | 0.336870 |
="key", y="val") px.box(dat, x
28.2 Histogram
px.histogram(x)
="val", color="key") px.histogram(dat, x
28.3 Scatter
= np.random.randn(300);
x = 3 + x**3 + np.random.randn(300);
y = 4 + x**2 + np.random.randn(300); y2
=x, y=y) px.scatter(x
=x, y=[y, y2]) px.scatter(x
28.4 Barplot
= np.array(["alpha", "beta", "gamma"])
x = np.array([3, 9, 5])
y = np.array([5, 8, 7]) y2
=x, y=y) px.bar(x