file_format | kernelspec | ||||
---|---|---|---|---|---|
mystnb |
|
% 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
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.
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
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.
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:
.. 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)
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
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
ipyleaflet
is a Jupyter/Leaflet bridge enabling interactive maps in the Jupyter notebook environment. this demonstrate how you can integrate maps in your documentation.
from ipyleaflet import Map, basemaps
# display a map centered on France
m = Map(basemap=basemaps.Esri.WorldImagery, zoom=5, center=[46.21, 2.21])
m