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.311370 0.930760 0.734203 -0.395752 -0.386222 1.944687 -0.914829 0.005161 -0.244122 -3.068303 ... -1.235248 -0.423947 -0.567292 -0.803213 1.277616 -0.981038 -2.517454 0.150340 -0.221287 0.120588
1 1.016465 -1.309161 0.119732 -0.193135 0.712014 0.661093 -0.426137 0.341819 -0.523607 1.622394 ... -2.695233 0.617742 0.550230 0.523802 0.059442 -0.220915 -0.421106 -0.001800 -0.752967 2.759070
2 1.868318 -0.746607 -0.353970 0.379558 -1.223273 -0.165177 0.020974 -0.095447 -0.094138 0.173706 ... 0.592267 -0.186192 -0.783239 -0.462316 1.416612 -0.572427 0.169302 0.702257 -2.506094 -1.552825
3 -1.280711 0.899626 -0.141591 2.274749 0.735301 0.312153 -1.339304 1.611907 -0.102241 0.312316 ... -0.496129 -0.160148 1.677369 0.903861 -1.288931 0.659441 1.748047 0.433460 -0.351234 0.737601
4 0.522139 -0.499206 -0.078972 -0.352476 0.954266 -1.256487 0.300661 -2.324879 -0.656328 -0.118312 ... 1.043888 0.120722 -0.555673 -1.478972 -0.073858 -2.286886 0.391620 -1.204539 0.292303 -0.056930
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
95 1.427196 0.180431 0.219939 1.645893 0.076371 -1.224770 -0.127598 -0.787070 0.372666 0.378871 ... 0.261914 0.079047 -0.109846 0.522169 0.252848 -1.285432 -1.454377 -0.096430 -0.729139 -0.229617
96 1.178522 -0.387039 -0.057630 -0.616969 0.767219 1.017275 -2.237077 -0.524710 2.090364 -1.114673 ... 2.276190 0.120314 -0.162370 0.176529 0.253103 0.532922 1.187715 -0.153143 0.752273 -2.186103
97 -0.218750 1.231444 0.832591 0.404316 0.668349 -1.194827 0.146782 -1.196502 1.033414 -1.438118 ... -1.682289 -0.501897 1.262362 -0.057749 0.251065 1.472893 -0.786191 3.407656 0.391525 1.285357
98 -2.219993 0.759655 -0.374613 -1.397357 1.627095 -1.876407 0.266039 -0.946892 -0.422397 -0.463645 ... -0.066578 2.735865 0.595039 0.183309 0.871685 -0.293767 -0.675990 -1.077739 -0.488007 -0.929621
99 0.473812 -0.050464 1.006873 -0.102286 0.710749 0.525634 -0.455428 1.479328 -0.640018 0.087520 ... -0.180498 0.048829 -0.207480 0.760001 1.218511 0.480343 -2.205869 -0.754764 0.776454 -0.889203

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 0x7f2198a2ee50>
../_images/9f2cc868fe16179e933bbe266f62d9d00e334f160d887a04f4d3b9f18a80bf34.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