aymeric-spiga / planetoplot

a cool python-based tool to plot stuff and explore data
https://github.com/aymeric-spiga/planetoplot/blob/master/README.md
GNU General Public License v2.0
10 stars 4 forks source link

use of cartopy #13

Open aymeric-spiga opened 5 years ago

aymeric-spiga commented 5 years ago

replace basemap by cartopy proposed by @jbmadeleine

aymeric-spiga commented 5 years ago

standalone example

#! /usr/bin/env python

#import ppplot
import numpy as np

b = np.arange(2048).reshape(32,64)
lon = np.linspace(-180,180,64)
lat = np.linspace(-90,90,32)

print(b.shape)
print(lon.shape)
print(lat.shape)

#ppplot.quickplot(b)

import cartopy.crs as ccrs
import matplotlib.pyplot as plt

prj = ccrs.Mollweide()
prj = ccrs.Orthographic(-10, 45)
#prj = ccrs.NorthPolarStereo()

ax = plt.axes(projection=prj)
#ax.set_xticks(range(-180,180,10), crs=ccrs.NorthPolarStereo())
#ax.set_yticks(range(-90,90,10), crs=ccrs.NorthPolarStereo())

ax.set_global()
#ax.gridlines() 
ax.gridlines(draw_labels=True)
ax.contourf(lon,lat,b,transform=ccrs.PlateCarree())
plt.show()
aymeric-spiga commented 5 years ago

Traceback (most recent call last): File "./test.py", line 32, in ax.gridlines(draw_labels=True) File "/home/aspiga/soft/conda/miniconda2/envs/cartopy/lib/python2.7/site-packages/cartopy/mpl/geoaxes.py", line 1215, in gridlines ylocator=ylocs, collection_kwargs=kwargs) File "/home/aspiga/soft/conda/miniconda2/envs/cartopy/lib/python2.7/site-packages/cartopy/mpl/gridliner.py", line 185, in init self._assert_can_draw_ticks() File "/home/aspiga/soft/conda/miniconda2/envs/cartopy/lib/python2.7/site-packages/cartopy/mpl/gridliner.py", line 399, in _assert_can_draw_ticks 'supported.'.format(prj=self.axes.projection)) TypeError: Cannot label gridlines on a Orthographic plot. Only PlateCarree and Mercator plots are currently supported.

aymeric-spiga commented 5 years ago

This might be solved soon? https://github.com/SciTools/cartopy/issues/881 https://github.com/SciTools/cartopy/pull/1089

aymeric-spiga commented 5 years ago

The question is whether it is useful to do so, or if replacing planetoplot by something based on xarray is not a better solution see https://github.com/aymeric-spiga/planetoplot/issues/8

aymeric-spiga commented 5 years ago

Looks like some progress is made in cartopy getting the labels like in matplotlib https://github.com/SciTools/cartopy/pull/1117