Map Projection (using Cartopy)
This page introduces a program that plots monthly temperature at each station on a map.
Monthly dataset
If data has a higher time resolution than the monthly average, you need to calculate the monthly average.
# Monthly average
m1 = df1.resample('1M').mean()
Monthly temperature plots on a map
Cartopy install
The map projection uses cartopy package.
The information on cartopy installation is available here.
You can simply command $ conda install -n env_weclim -c conda-forge cartopy
.
Map plots
The background map can be drawn using the following commends:
import cartopy.crs as crs
plt.rcParams.update({'font.size': 15})
# map projections and state boundary lines
ax = fig.add_subplot(1,1,1, projection=crs.PlateCarree())
ax.stock_img()
ax.add_feature(cfeature.STATES)
# map area setting
ax.set_extent([-115, -108, 36, 43],
The monthly temperature can be plots at each location using pandas.DataFrame.plot
command (command information).
# Define dictionary for kwargs
kwargs = dict(
vmin = -20.0,
vmax = 40.0,
transform=crs.PlateCarree(), # ds projection
)
# add grid
ax.gridlines(draw_labels=True, crs=crs.PlateCarree())
dfig.plot(x="Lon", y="Lat", kind="scatter", c="TAIR",
title = "Air Temperature ("+titleX+")", s=200,
colormap="jet", ax=ax, **kwargs)
plt.draw()
Sample program for maps
Source file: maps.temp.py
Create animation
PNG files can be converted to animated images (gif file).
convert -delay 50 -loop 3 ${figdir}/*.png TAIR.gif
Here, -delay N
is the frame rate of N/100 (seconds) and -loop M
is the number of loop of the animation image.
You can check the animation image as $ animate XX.gif
.