---
file_format: mystnb
kernelspec:
  name: python3
  display_name: Python 3
---

% To test this file with nbsphinx we need to convert to ipynb. To do this:
% - Run this command: jupytext docs/examples/pydata.md --to ipynb
% - _Temporarily_ delete the pydata.md file
% - Uncomment `nbsphinx` and comment `myst_nb` in "extensions" in our conf.py file
% - Build the docs and test that the results look OK
% - Undo everything in this list to make sure we revert back to the old structure

# 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

```{code-cell}
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
```

## Matplotlib

```{sidebar}
Here's a sidebar to test that the code cells behave as we'd expect when there is content to the right. The code cell should be displayed to the left and with no overlap.
```

```{code-cell}
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.scatter(df["a"], df["b"], c=df["b"], s=3)
```

and with the Matplotlib `plot` directive:

```{eval-rst}
.. plot::

   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)
```

## 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.

```{code-cell}
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.

```{code-cell}
import xarray as xr
data = xr.DataArray(
        np.random.randn(2, 3),
        dims=("x", "y"),
        coords={"x": [10, 20]}, attrs={"foo": "bar"}
      )
data
```

## `jupyter-sphinx`

Another common library is `jupyter-sphinx`.
This section demonstrates a subset of functionality above to make sure it behaves as expected.

```{jupyter-execute}
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)
```
