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

Plotting overlapping features #1318

Closed
karlwx opened this issue Jun 8, 2019 · 1 comment
Closed

Plotting overlapping features #1318

karlwx opened this issue Jun 8, 2019 · 1 comment

Comments

@karlwx
Copy link

karlwx commented Jun 8, 2019

Description

This is a relatively minor issue, but I've noticed that when I pull in some natural earth features to plot, such as states, coastlines, etc, that even when I set the linewidth of all features to be the same (in this case 0.5), I still end up with inconsistencies in the line size plotted (notice the difference in state boundary size vs the border between US and Mexico in the attached image).

I believe this is because when features overlap, and are plotted on top of one another, the line size will increase even if it is the same. I guess the way to get around this would be to use a GIS program to merge all the features you want to plot into a single shapefile .

It would be nice for cartopy to have a built in tool to keep the line size consistent - either through merging features or preventing plotting of overlapping features. That was one of the nicest things about Basemap - the states, counties, counties, and coastline were baked-in, and didn't cause any issue with overlap and incorrect sizing.

Code to reproduce

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

def states_coastline(ax, resolution='50m', linewidth=0.5, color='black', states=True):

	ax.coastlines(resolution=resolution, color=color, linewidth=linewidth)

	states_provinces = cfeature.NaturalEarthFeature(
		    category='cultural',
		    name='admin_1_states_provinces_lakes',
		    scale=resolution,
		    facecolor='none')
	if states:	    
		ax.add_feature(states_provinces, edgecolor=color, linewidth=linewidth)

fig = plt.figure(figsize=(15, 12))

proj = ccrs.LambertConformal()
ax = fig.add_subplot(1, 1, 1, projection=proj)

ax.set_extent([-160,-40,20,75], crs=ccrs.PlateCarree())

states_coastline(ax, resolution='50m', linewidth=0.5, color='black')

states

@dopplershift
Copy link
Contributor

So, I don't think it's a problem with the map information--these data all come from the Natural Earth datasets, and I think all of those datasets are consistent with themselves.

I think what you're seeing is:

  1. 50m scale is a bit overkill at this map extent, and the high resolution coastlines just become big blobs of black.
  2. I can reproduce some darker lines when I go to 110m scale. In this case, I think what you're seeing is an artifact of your 0.5 linewidth. At that fine of a line, I think the renderer has to use some transparency to produce smooth (anti-aliased) lines. When multiple of those lines is drawn on top of each other, the partially transparent pixels add together and produce darker spots. Actually, the fact that all of those lines are so perfectly darker means the map information is lining up perfectly.

You can see the difference if you pass antialiased=False to coastlines and add_feature. If you do so, then the map looks like this:

image

So, not an issue with the natural earth map information as far as I can tell, but if I'm mistaken please do show me.

I also wanted to note that you could simplify your code above by using cartopy's built in cartopy.feature.STATES rather than manually making an instance of NaturalEarthFeature.

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