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