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 0.337832 1.015507 -2.425079 0.718822 0.476711 0.242744 -0.710911 0.051611 0.458924 -1.234185 ... 0.152928 0.347723 -0.588033 -0.768418 -0.457759 -0.144539 0.482148 -0.208461 0.113157 -2.007067
1 0.611565 -0.509853 1.521159 0.838770 1.361020 0.132129 0.684329 0.887770 1.180494 0.572619 ... 0.906607 -0.310715 -0.590912 -0.643633 -0.396196 -0.153815 -0.708665 -0.656567 -1.200973 -0.932478
2 -0.431345 0.732481 -0.466144 -0.911873 0.317994 1.495503 1.194962 0.878642 1.336481 -0.683890 ... 0.573093 0.089960 -1.772773 0.011609 -0.432426 0.039939 0.926707 -0.425309 -0.099011 0.456347
3 1.048645 0.001106 0.420312 2.491772 2.087056 0.673955 1.850538 -0.258097 0.114133 0.531730 ... -0.803633 1.138408 1.250955 0.249347 -0.105939 -0.841896 1.189338 -0.468783 0.611198 -1.490064
4 -0.976704 -0.165272 -0.479563 -0.407338 1.163062 0.580717 -0.184668 -0.345560 -0.365044 0.647861 ... -1.024688 -0.590177 2.564140 1.325173 -0.469921 1.276761 0.596876 -0.759682 -0.848470 1.260400
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
95 -1.742328 -0.820177 0.774694 0.162223 0.036031 0.120207 1.146157 0.056860 -0.258306 -0.815839 ... -0.112124 0.209321 -0.165929 1.750585 2.136611 0.211838 -0.705679 0.112627 -1.075042 -0.575852
96 -0.071232 0.005755 -1.421235 -1.558559 -1.556884 -1.261193 0.537390 1.651588 0.279433 -0.373941 ... 0.111178 0.511720 0.182704 -1.045835 0.438071 -1.656922 0.389596 -0.302977 -0.715121 -1.254161
97 1.159380 -0.297939 0.950482 0.518170 1.764782 0.063064 0.915259 1.465723 0.734033 -0.815478 ... -0.683592 0.326329 0.349121 1.013914 -0.702466 -0.022289 -0.400786 1.177755 0.609642 -0.878732
98 0.401734 -2.026026 0.899918 0.034704 -0.929748 0.438229 0.436013 0.854946 -1.348165 -0.825123 ... -1.576792 -2.128186 -1.427433 0.642791 -0.396001 -0.093596 1.060976 2.110835 0.265141 0.424460
99 -0.172867 -1.680150 -0.634300 1.563591 0.803069 1.874748 -0.869536 1.217303 -0.004136 0.191005 ... -0.162731 0.465329 0.913760 1.427201 -0.094578 0.170527 -1.505829 -0.932026 -0.497174 -0.682389

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 0x7fcba0935af0>
../_images/5b5a5c293dd47a28180c52b771714e945ae2fa58750b1dd1680fb9a6fbe85496.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