Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatiable with polar projectoin with cartopy 0.20 #307

Closed
zxdawn opened this issue Dec 8, 2021 · 6 comments
Closed

Compatiable with polar projectoin with cartopy 0.20 #307

zxdawn opened this issue Dec 8, 2021 · 6 comments

Comments

@zxdawn
Copy link

zxdawn commented Dec 8, 2021

Description

As discussed in #246, the latinline doesn't work with the new version of cartopy. Although the new cartopy also has some problem of showing lonlabels ...

Steps to reproduce

import proplot as pplt
import numpy as np

pplt.rc['cartopy.circular'] = False

fig, axs = pplt.subplots(proj='npstere')

axs.format(coast=True, reso='med',
           latlines=5, latinline=True, lonlabels='lrbt',
           boundinglat=60
           )

Expected behavior: [What you expected to happen]

The lat labels are shown inline.

Actual behavior: [What actually happened]

image

Equivalent steps in matplotlib

import numpy as np
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

ax = plt.subplot(111, projection=ccrs.NorthPolarStereo())
gl = ax.gridlines(color='r', draw_labels=True, x_inline =False, y_inline =True)

polar_extent = [-180, 180, 60, 80]
ax.set_extent(polar_extent, crs=ccrs.PlateCarree())

gl.ylocator = mticker.FixedLocator(np.arange(60, 90, 5))
gl.xlocator = mticker.FixedLocator(np.arange(-180, 180, 60))

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)here.

3.5.0
0.9.5
@lukelbd
Copy link
Collaborator

lukelbd commented Jan 21, 2022

For future reference here is what this should look like (using cartopy 0.19).

tmp

@lukelbd
Copy link
Collaborator

lukelbd commented Jan 21, 2022

And here's what this looks like in matplotlib + cartopy alone (version 0.20):

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

fig, ax = plt.subplots(subplot_kw={'projection': ccrs.NorthPolarStereo()})
ax.set_extent([-180, 180, 0, 90], ccrs.PlateCarree())
ax.coastlines()
ax.gridlines(
    draw_labels=True,
    x_inline=True,
    y_inline=True,
    ylim=(0, 80),
)

cartopy

@lukelbd
Copy link
Collaborator

lukelbd commented Jan 21, 2022

Fixed this, along with what seems to be a cartopy 0.20 issue with setting longitude/latitude label sides using format. Here's an example. Note that I've renamed cartopy.circular and circular to geo.round and round to be more succinct, and because I now apply round to basemap polar maps too. Using the old keywords emits a deprecation warning.

import proplot as pplt
fig, ax = pplt.subplot(
   proj='npstere', round=False, boundinglat=30, lonlabels='lrbt', latinline=True, coast=True
)

tmp

@zxdawn
Copy link
Author

zxdawn commented Jan 21, 2022

Thanks a lot, Luke! Did you also get some warnings when running your code above? (matplotlib: 3.5.1; proplot: master; cartopy: 0.20.1)

CLICK TO SEE WARNING
/home/xin/Documents/github/proplot/proplot/__init__.py:71: ProplotWarning: Rebuilding font cache. This usually happens after installing or updating proplot.
  register_fonts(default=True)
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:842: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  elif len(intersection) > 4:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:853: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for inter in intersection:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:842: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  elif len(intersection) > 4:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:853: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for inter in intersection:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:842: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  elif len(intersection) > 4:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:853: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for inter in intersection:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:842: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  elif len(intersection) > 4:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:853: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for inter in intersection:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:842: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  elif len(intersection) > 4:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:853: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for inter in intersection:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:842: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  elif len(intersection) > 4:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:853: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for inter in intersection:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:842: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  elif len(intersection) > 4:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/mpl/gridliner.py:853: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for inter in intersection:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/crs.py:825: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(multi_line_string) > 1:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/crs.py:877: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  for line in multi_line_string:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/crs.py:944: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  if len(p_mline) > 0:
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/crs.py:982: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
  line_strings.extend(multi_line_string)
/home/xin/miniconda3/lib/python3.9/site-packages/cartopy/crs.py:982: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  line_strings.extend(multi_line_string)

@lukelbd
Copy link
Collaborator

lukelbd commented Jan 21, 2022

It looks like this is a cartopy issue with the latest shapely fixed in SciTools/cartopy#1913 (added in the cartopy 0.20.2 release). Alternatively you can downgrade shapely. For the website documentation I use conda install shapely==1.7.1.

@zxdawn
Copy link
Author

zxdawn commented Jan 21, 2022

Got it. Updating cartopy to 0.20.2 fixes this ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants