None

Note

This tutorial was generated from an IPython notebook that can be downloaded here.

# Plotting¶

Every region has two plotting functions, which draw the outlines of all regions:

• `plot`: draws the region polygons on a cartopy GeoAxes (map)

• `plot_regions`: draws the the region polygons only

Import regionmask and check the version:

```import regionmask

```
```'0.8.1.dev0+gc47cc00.d20210908'
```

We use the srex regions to illustrate the plotting:

```srex = regionmask.defined_regions.srex
srex
```
```<regionmask.Regions>
Name:     SREX
Source:   Seneviratne et al., 2012 (https://www.ipcc.ch/site/assets/uploads/2...

Regions:
3 WNA         W. North America
4 CNA         C. North America
5 ENA         E. North America
..  ..                      ...
22 EAS                  E. Asia
23 SAS                  S. Asia
24 SEA                S.E. Asia
25 NAU             N. Australia
26 SAU S. Australia/New Zealand

[26 regions]
```

## Plot all regions¶

Calling `plot()` on any region without any arguments draws the default map with a `PlateCarree()` projection and includes the coastlines:

```srex.plot();
``` ## Plot options¶

The `plot` method has a large number of arguments to adjust the layout of the axes. For example, you can pass a custom projection, the labels can display the abbreviation insead of the region number, the ocean can be colored, etc.. This example also shows how to use `matplotlib.patheffects` to ensure the labels are easily readable without covering too much of the map (compare to the map above):

```import cartopy.crs as ccrs
import matplotlib.patheffects as pe

text_kws = dict(
bbox=dict(color="none"),
path_effects=[pe.withStroke(linewidth=2, foreground="w")],
color="#67000d",
fontsize=8,
)

ax = srex.plot(
)

ax.set_global()
``` ## Plot only a Subset of Regions¶

To plot a selection of regions subset them using indexing:

```# regions can be selected by number, abbreviation or long name
regions = [11, "CEU", "S. Europe/Mediterranean"]

# choose a good projection for regional maps
proj = ccrs.LambertConformal(central_longitude=15)

ax = srex[regions].plot(
resolution="50m",
proj=proj,
label="abbrev",
)

# fine tune the extent
ax.set_extent([-15, 45, 28, 76], crs=ccrs.PlateCarree())
``` ## Plotting the region polygons only (no map)¶

```srex.plot_regions();
``` Note

This does not create a cartopy GeoAxes.

To achieve this, you need to explicitely create the axes:

```import matplotlib.pyplot as plt

f, ax = plt.subplots(subplot_kw=dict(projection=ccrs.Robinson()))

srex.plot_regions(ax=ax, line_kws=dict(lw=1))

ax.coastlines()
ax.set_global()
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5269231,"math_prob":0.85248387,"size":2553,"snap":"2021-43-2021-49","text_gpt3_token_len":697,"char_repetition_ratio":0.10945469,"word_repetition_ratio":0.0,"special_character_ratio":0.2557775,"punctuation_ratio":0.2019802,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97342014,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,2,null,2,null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-26T18:25:37Z\",\"WARC-Record-ID\":\"<urn:uuid:5a9fac23-1e2c-4136-8e8d-c1440e42165f>\",\"Content-Length\":\"24700\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5a26ea0b-400e-4659-858f-31a8d0c9c34c>\",\"WARC-Concurrent-To\":\"<urn:uuid:9c4f75d5-a33b-4c37-b2db-1cd2b264e6f7>\",\"WARC-IP-Address\":\"104.17.32.82\",\"WARC-Target-URI\":\"https://regionmask.readthedocs.io/en/stable/notebooks/plotting.html\",\"WARC-Payload-Digest\":\"sha1:C5HPMLVGJQUW3RVUQQDG3BINHW6SIHL5\",\"WARC-Block-Digest\":\"sha1:3XRMFS7P5WHCJCQX5O35UE547PGQ2RII\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323587915.41_warc_CC-MAIN-20211026165817-20211026195817-00050.warc.gz\"}"}