PyData Library Styles#
This theme has built-in support and special styling for several major visualization libraries in the PyData ecosystem. This ensures that the images and output generated by these libraries looks good for both light and dark modes. Below are examples of each that we use as a benchmark for reference.
Pandas#
import numpy as np
import pandas as pd
rng = np.random.default_rng()
data = rng.standard_normal((100, 3))
df = pd.DataFrame(data, columns=['a', 'b', 'c'])
df
a | b | c | |
---|---|---|---|
0 | 0.544248 | 2.579997 | 1.399369 |
1 | -0.332872 | -0.788556 | -1.001929 |
2 | -0.269093 | 0.125202 | 0.309308 |
3 | 1.370383 | 0.789741 | 0.390290 |
4 | 0.272635 | -2.389736 | 0.517645 |
... | ... | ... | ... |
95 | 2.022357 | -1.353882 | 0.582298 |
96 | 0.801067 | -0.233574 | -0.673436 |
97 | -0.258899 | -1.119459 | -0.697822 |
98 | 0.341337 | 1.005810 | 0.513304 |
99 | -1.665114 | 0.143590 | 1.179589 |
100 rows × 3 columns
Matplotlib#
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter(df["a"], df["b"], c=df["b"], s=3)
<matplotlib.collections.PathCollection at 0x7fb7eb94d2d0>
and with the Matplotlib plot
directive:
(Source code, png, hires.png, pdf)
Plotly#
The HTML below shouldn’t display, but it uses RequireJS to make sure that all works as expected. If the widgets don’t show up, RequireJS may be broken.
import plotly.io as pio
import plotly.express as px
import plotly.offline as py
pio.renderers.default = "notebook"
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size="sepal_length")
fig
Xarray#
Here we demonstrate xarray
to ensure that it shows up properly.
import xarray as xr
data = xr.DataArray(
np.random.randn(2, 3),
dims=("x", "y"),
coords={"x": [10, 20]}, attrs={"foo": "bar"}
)
data
<xarray.DataArray (x: 2, y: 3)> array([[-1.29449293, -0.72143841, -1.37105259], [-0.85442552, 0.04269159, 1.58084385]]) Coordinates: * x (x) int64 10 20 Dimensions without coordinates: y Attributes: foo: bar
jupyter-sphinx
#
Another common library is jupyter-sphinx
.
This section demonstrates a subset of functionality above to make sure it behaves as expected.
import matplotlib.pyplot as plt
import numpy as np
rng = np.random.default_rng()
data = rng.standard_normal((3, 100))
fig, ax = plt.subplots()
ax.scatter(data[0], data[1], c=data[2], s=3)
<matplotlib.collections.PathCollection at 0x7f169881c7c0>