forked from pydata/xarray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gallery example for multiple lines plot (pydata#1808)
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
================================== | ||
Multiple lines from a 2d DataArray | ||
================================== | ||
Use :py:func:`xarray.plot.line` on a 2d DataArray to plot selections as | ||
multiple lines. | ||
See :ref:`plotting.multiplelines` for more details. | ||
""" | ||
|
||
import xarray as xr | ||
import matplotlib.pyplot as plt | ||
|
||
# Load the data | ||
ds = xr.tutorial.load_dataset('air_temperature') | ||
air = ds.air - 273.15 # to celsius | ||
|
||
# Prepare the figure | ||
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharey=True) | ||
|
||
# Selected latitude indices | ||
isel_lats = [10, 15, 20] | ||
|
||
# Temperature vs longitude plot - illustrates the "hue" kwarg | ||
air.isel(time=0, lat=isel_lats).plot.line(ax=ax1, hue='lat') | ||
ax1.set_ylabel('°C') | ||
|
||
# Temperature vs time plot - illustrates the "x" and "add_legend" kwargs | ||
air.isel(lon=30, lat=isel_lats).plot.line(ax=ax2, x='time', add_legend=False) | ||
ax2.set_ylabel('') | ||
|
||
# Show | ||
plt.tight_layout() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters