Skip to content

Commit f7eb309

Browse files
authored
Add sphinx-gallery to the docs (#1419)
* Add sphinx-gallery to the docs * Whats new * Move to examples * Rename to recipes
1 parent d802484 commit f7eb309

8 files changed

+113
-0
lines changed

Diff for: doc/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ help:
4848
clean:
4949
rm -rf $(BUILDDIR)/*
5050
rm -rf generated/*
51+
rm -rf auto_gallery/
5152

5253
.PHONY: html
5354
html:
@@ -67,6 +68,12 @@ singlehtml:
6768
@echo
6869
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
6970

71+
.PHONY: html-noplot
72+
html-noplot:
73+
$(SPHINXBUILD) -D plot_gallery=0 -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
74+
@echo
75+
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
76+
7077
.PHONY: pickle
7178
pickle:
7279
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle

Diff for: doc/conf.py

+6
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@
9191
'numpydoc',
9292
'IPython.sphinxext.ipython_directive',
9393
'IPython.sphinxext.ipython_console_highlighting',
94+
'sphinx_gallery.gen_gallery',
9495
]
9596

9697
extlinks = {'issue': ('https://github.com/pydata/xarray/issues/%s', 'GH'),
9798
'pull': ('https://github.com/pydata/xarray/pull/%s', 'PR'),
9899
}
99100

101+
sphinx_gallery_conf = {'examples_dirs': 'gallery',
102+
'gallery_dirs': 'auto_gallery',
103+
'backreferences_dir': False
104+
}
105+
100106
autosummary_generate = True
101107

102108
numpydoc_class_members_toctree = True

Diff for: doc/environment.yml

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ dependencies:
1515
- netCDF4=1.2.5
1616
- hdf4=4.2.12 # temporary install to get netCD4 working (GH1106)
1717
- cartopy=0.14.3
18+
- pip:
19+
- sphinx-gallery

Diff for: doc/examples.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Examples
88
examples/weather-data
99
examples/monthly-means
1010
examples/multidimensional-coords
11+
auto_gallery/index

Diff for: doc/gallery/README.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. _recipes:
2+
3+
Recipes
4+
=======
5+

Diff for: doc/gallery/plot_cartopy_facetgrid.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
==================================
4+
Multiple plots and map projections
5+
==================================
6+
7+
Control the map projection parameters on multiple axes
8+
9+
This example illustrates how to plot multiple maps and control their extent
10+
and aspect ratio.
11+
12+
For more details see `this discussion`_ on github.
13+
14+
.. _this discussion: https://github.com/pydata/xarray/issues/1397#issuecomment-299190567
15+
"""
16+
17+
import xarray as xr
18+
import cartopy.crs as ccrs
19+
import matplotlib.pyplot as plt
20+
21+
# Load the data
22+
ds = xr.tutorial.load_dataset('air_temperature')
23+
air = ds.air.isel(time=[0, 724]) - 273.15
24+
25+
# This is the map projection we want to plot *onto*
26+
map_proj = ccrs.LambertConformal(central_longitude=-95, central_latitude=45)
27+
28+
p = air.plot(transform=ccrs.PlateCarree(), # the data's projection
29+
col='time', col_wrap=1, # multiplot settings
30+
aspect=ds.dims['lon']/ds.dims['lat'], # for a sensible figsize
31+
subplot_kws={'projection': map_proj}) # the plot's projection
32+
33+
# We have to set the map's options on all four axes
34+
for ax in p.axes.flat:
35+
ax.coastlines()
36+
ax.set_extent([-160, -30, 5, 75])
37+
# Without this aspect attributes the maps will look chaotic and the
38+
# "extent" attribute above will be ignored
39+
ax.set_aspect('equal', 'box-forced')
40+
41+
plt.show()

Diff for: doc/gallery/plot_colorbar_center.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
==================
4+
Centered colormaps
5+
==================
6+
7+
xarray's automatic colormaps choice
8+
9+
"""
10+
11+
import xarray as xr
12+
import matplotlib.pyplot as plt
13+
14+
# Load the data
15+
ds = xr.tutorial.load_dataset('air_temperature')
16+
air = ds.air.isel(time=0)
17+
18+
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(8, 6))
19+
20+
# The first plot (in kelvins) chooses "viridis" and uses the data's min/max
21+
air.plot(ax=ax1, cbar_kwargs={'label':'K'})
22+
ax1.set_title('Kelvins: default')
23+
ax2.set_xlabel('')
24+
25+
# The second plot (in celsius) now chooses "BuRd" and centers min/max around 0
26+
airc = air - 273.15
27+
airc.plot(ax=ax2, cbar_kwargs={'label':'°C'})
28+
ax2.set_title('Celsius: default')
29+
ax2.set_xlabel('')
30+
ax2.set_ylabel('')
31+
32+
# The center doesn't have to be 0
33+
air.plot(ax=ax3, center=273.15, cbar_kwargs={'label':'K'})
34+
ax3.set_title('Kelvins: center=273.15')
35+
36+
# Or it can be ignored
37+
airc.plot(ax=ax4, center=False, cbar_kwargs={'label':'°C'})
38+
ax4.set_title('Celsius: center=False')
39+
ax4.set_ylabel('')
40+
41+
# Mke it nice
42+
plt.tight_layout()
43+
plt.show()

Diff for: doc/whats-new.rst

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ By `Keisuke Fujii <https://github.com/fujiisoup>`_.
5252
successful download (:issue:`1392`). By `Matthew Gidden
5353
<https://github.com/gidden>`_.
5454

55+
Documentation
56+
~~~~~~~~~~~~~
57+
58+
- A new `gallery <http://xarray.pydata.org/en/latest/auto_gallery/index.html>`_
59+
allows to add interactive examples to the documentation.
60+
By `Fabien Maussion <https://github.com/fmaussion>`_.
61+
62+
5563
.. _whats-new.0.9.5:
5664

5765
v0.9.5 (17 April, 2017)

0 commit comments

Comments
 (0)