pysal / splot

Lightweight plotting for geospatial analysis in PySAL
BSD 3-Clause "New" or "Revised" License
98 stars 26 forks source link

Hatching/Fill methods? #35

Open ljwolf opened 6 years ago

ljwolf commented 6 years ago

After reading "Choropleth Maps without Class Intervals?", I wonder whether there's a way we can get cross-hatching on fill styles for maps? The new Shelton & Poorthuis preprint uses some crosshatching for visual effect, and I think it looks better in black/white settings.

I'll probably dig into this at some point, but wanted to log this for posterity/in case someone else wants to run with this.

martinfleis commented 4 years ago

This can be quite simple to implement using matplotlib hatches. You specify them as strings, like '+' and you control the density by multiplying the symbol ('+++'). See the example below:

import matplotlib.pyplot as plt
from shapely.geometry import Point
import geopandas as gpd

fig, ax = plt.subplots(figsize=(16, 3))
for i in range(1, 7):
    gpd.GeoSeries([Point(i, 0).buffer(.4)]).plot(hatch='+' * i, ax=ax, facecolor='none', edgecolor='k')

download

for i in range(1, 7):
    gpd.GeoSeries([Point(i, 0).buffer(.4)]).plot(hatch='\\' * i, ax=ax, facecolor='none', edgecolor='k')

download-1

Note that you can have only a single hatch per collection, can't be passed as a list.

ljwolf commented 4 years ago

Ooh, rad, that's very close to what I was hoping for!

I suppose the intent was to be able to make a hatch_map function, like the existing value_by_alpha map, that allowed you to vary the density of the hatching along with (or independent of) the color ramp. This would be a way to get an alternative bivariate choropleth strategy, varying hatching & hue instead of mixing two hues. With what you've shown above, that should definitely be possible by stratifying the data by hatching, then coloring the symbols...