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

weird output when using central_longitude != 0 #2412

Open
JosephBARBIERDARNAL opened this issue Jul 3, 2024 · 3 comments
Open

weird output when using central_longitude != 0 #2412

JosephBARBIERDARNAL opened this issue Jul 3, 2024 · 3 comments

Comments

@JosephBARBIERDARNAL
Copy link

Description

When using central_longitude=10, the output chart becomes unvalid with some horizontal lines (seems to be Canada being deformed in the case below).

  • This (seems to) works for any value centra_longitude different of 0.
  • Same for other projection (I haven't tried them all)

Since the error is a bit too obvious, I doubt I'm first one having the issue, but I haven't found something similar on the internet/issues. Is it an expected behavior?

Code to reproduce

This is a copy-pastable example:

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

proj = ccrs.Mercator(central_longitude=10)

url = "https://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/all_world.geojson"
world = gpd.read_file(url)
world = world[~world['name'].isin(["Antarctica", "Greenland"])]
world = world.to_crs(proj.proj4_init)

fig, ax = plt.subplots(figsize=(12, 8), dpi=300, subplot_kw={'projection':proj})
ax.set_axis_off()
world.boundary.plot(ax=ax)
plt.show()
Screenshot 2024-07-03 at 15 30 42

Traceback

None

Operating system

MacOS Sonoma

Cartopy version

0.23.0

@lgolston
Copy link
Contributor

lgolston commented Jul 5, 2024

Yes, I think it is expected (see note in geopandas docs about objects crossing the dateline: https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.to_crs.html)

Here is a different version that should be working:

proj = ccrs.Mercator(central_longitude=10)

url = "https://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/all_world.geojson"
world = gpd.read_file(url)
world = world[~world['name'].isin(["Antarctica", "Greenland"])]

fig, ax = plt.subplots(figsize=(12, 8), dpi=300, subplot_kw={'projection':proj})
ax.add_geometries(world["geometry"], crs=ccrs.PlateCarree(), facecolor='none')
plt.show()

@schlunma

This comment was marked as duplicate.

@schlunma
Copy link

I opened a new issue for the problem described above; this also happens for central_longitude=0.0.

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

No branches or pull requests

3 participants