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 string

import numpy as np
import pandas as pd

rng = np.random.default_rng()
data = rng.standard_normal((100, 26))
df = pd.DataFrame(data, columns=list(string.ascii_lowercase))
df
a b c d e f g h i j ... q r s t u v w x y z
0 -1.830258 0.347521 0.617913 -0.785232 0.154458 -0.250461 -0.312718 -0.578558 0.767104 -0.428502 ... 2.622064 -1.030765 0.896598 0.778476 -0.621801 -1.175479 -0.960836 -0.089926 0.891184 0.691210
1 2.038287 0.883925 -0.541604 -0.969061 -2.383186 -0.036589 0.339397 0.975940 -0.724568 1.989548 ... 0.691389 0.326559 -1.236894 2.152040 0.098790 -0.970509 0.911470 0.469763 0.111984 0.618193
2 -0.444968 -0.548629 0.517324 1.017793 0.256368 -0.737745 -0.734306 0.435746 0.069795 -0.931389 ... -1.489567 0.122636 0.124295 -0.678956 1.287661 -0.859396 -0.656106 -1.106629 0.811789 0.849594
3 -1.713605 -0.201987 1.242525 -0.059255 -0.826675 0.356628 -0.870699 0.418696 0.805607 -0.829078 ... -0.749157 -0.855752 0.097915 -0.141360 1.287956 -0.991525 -0.000608 0.653034 0.513235 -0.233824
4 -1.280956 -0.485510 -1.389025 0.503243 1.299015 0.202684 0.209122 -0.609362 -0.461734 -0.088465 ... 0.698877 -0.044061 0.412035 -1.376618 -1.867034 0.067669 0.227615 -0.172705 0.589123 -0.202529
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
95 -1.163986 -0.640898 2.281955 0.222181 -0.313488 1.550989 -0.467837 -0.544572 0.220804 -0.190542 ... 0.766402 1.046308 -2.014181 -0.927442 0.687624 1.325488 -0.478942 0.857854 1.772983 -0.133958
96 -0.755962 -0.821072 -1.093489 -2.492608 -0.875516 0.368558 0.988877 1.357628 0.800328 -2.963799 ... 0.856025 0.032298 0.592699 0.975476 0.001851 -0.155195 0.363299 1.801726 0.436223 -1.514875
97 -0.793758 -0.199138 0.837701 -1.353553 1.557879 0.443574 0.420751 0.668283 0.659848 -0.568411 ... 0.663857 -0.840527 1.388069 1.377045 1.223372 0.585533 -0.286536 -0.062491 0.955046 -0.458905
98 -0.225620 0.354094 0.026785 0.892811 -0.155761 -0.223902 0.459823 2.292512 -1.255871 -1.255020 ... -1.580055 -0.901833 0.514015 -2.008254 0.250479 0.594348 2.162004 0.006431 0.425658 -2.147766
99 1.581558 -0.321400 1.059851 -0.592495 0.541995 0.994483 -0.117742 -0.108034 0.192528 -1.607943 ... 0.625558 -1.200720 -0.033574 1.097674 1.751725 -1.759027 -0.597538 1.023980 0.714647 1.117965

100 rows × 26 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 0x7f250a2cf400>
../_images/2ab7d25c22654d8fa06c9a835820f2daad6d6af4e142f11a14dff9bd64ac52d7.png

and with the Matplotlib plot directive:

(Source code, png, hires.png, pdf)

../_images/pydata-1.png

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.45295616, -0.7404907 ,  0.07469895],
       [-0.52786457, -0.19619602,  3.50009945]])
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 0x7faa823180d0>
../_images/pydata_0_1.png