Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib basemap drawcounties doesn't work

Pretty much what the title says. My drawcounties command is just being ignored with no errors. Does it only plot on certain projections? The documentation doesn't say so.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap, shiftgrid
import scipy

def BasemapParameters():
    """
    Sets up basemap.
    """
    m = Basemap(projection='mill', llcrnrlon = 230, llcrnrlat = 27,
                                   urcrnrlat = 45, urcrnrlon = 261,
                                   area_thresh = 1000., resolution='i')
    m.drawcounties(linewidth=0.5)
    m.drawcoastlines(linewidth=0.7)
    m.drawcountries(linewidth=0.5)
    m.drawstates(linewidth=0.5)
    m.drawmapboundary(linewidth=0.7)

def SavePlot(lvl,parameter,region,hour,padding):
    """
    Saves figure to file with given properties
    """
    plt.savefig('{0}_{1}_{2}_{3}.png'.format(lvl,parameter,region,hour),bbox_inches='tight',pad_inches = padding)
    plt.close("all")
    print('  "{0}_{1}_{2}_{3}.png" created.'.format(lvl,parameter,region,hour))

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
BasemapParameters()
SavePlot('sfc','3hrpcp','sw','000',.07)

Output: enter image description here

like image 292
pythonismyjam Avatar asked Mar 08 '26 13:03

pythonismyjam


1 Answers

drawcoastlines() is plotting polygons with white faces, so that is going on top of the county lines.

like image 127
Ben Root Avatar answered Mar 10 '26 03:03

Ben Root



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!