matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
775 stars 392 forks source link

Using fillcontinents with color causes error #394

Closed ZelphirKaltstahl closed 6 years ago

ZelphirKaltstahl commented 6 years ago

I was following the following guide a bit: https://matplotlib.org/basemap/users/examples.html but when I tried the following simplified code:

# for deprecation warning check: https://github.com/matplotlib/basemap/issues/382

import numpy as np
from mpl_toolkits.basemap import Basemap  # basemap package
import matplotlib.pyplot as plt

# miller projection
map = Basemap(projection='mill',lon_0=0)
# plot coastlines, draw label meridians and parallels.
map.drawcoastlines(linewidth=0.5)
map.drawparallels(np.arange(-90,90,30),labels=[1,0,0,0], linewidth=0.3)
map.drawmeridians(np.arange(map.lonmin,map.lonmax+30,60),labels=[0,0,0,1], linewidth=0.3)
# fill continents 'coral' (with zorder=0), color wet areas 'aqua'
map.drawmapboundary(fill_color='white')
map.fillcontinents(color='coral',lake_color='aqua')
plt.show()

I got an error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-faa602d3f27d> in <module>()
     14 # fill continents 'coral' (with zorder=0), color wet areas 'aqua'
     15 map.drawmapboundary(fill_color='white')
---> 16 map.fillcontinents(color='coral',lake_color='aqua')
     17 #map.drawlsmask(color="coral")
     18 # shade the night areas, with alpha transparency so the

~/apps/anaconda3/envs/data-analyst-track-module-2/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py in fillcontinents(self, color, lake_color, ax, zorder, alpha)
   1765         ax = ax or self._check_ax()
   1766         # get axis background color.
-> 1767         axisbgc = ax.get_axis_bgcolor()
   1768         npoly = 0
   1769         polys = []

AttributeError: 'AxesSubplot' object has no attribute 'get_axis_bgcolor'

Used versions of libraries are (output of conda list, shortened):

numpy                     1.13.3           py36hdbf6ddf_4
basemap                   1.0.7               np113py36_0
matplotlib                2.2.2            py36h0e671d2_0
WeatherGod commented 6 years ago

update your install of basemap. Get it from conda-forge. It has the fix for this.

On Fri, Apr 6, 2018 at 5:58 AM, Zelphir Kaltstahl notifications@github.com wrote:

I was following the following guide a bit: https://matplotlib.org/ basemap/users/examples.html but when I tried the following simplified code:

for deprecation warning check: https://github.com/matplotlib/basemap/issues/382

import numpy as npfrom mpl_toolkits.basemap import Basemap # basemap packageimport matplotlib.pyplot as plt

miller projectionmap = Basemap(projection='mill',lon_0=0)# plot coastlines, draw label meridians and parallels.map.drawcoastlines(linewidth=0.5)map.drawparallels(np.arange(-90,90,30),labels=[1,0,0,0], linewidth=0.3)map.drawmeridians(np.arange(map.lonmin,map.lonmax+30,60),labels=[0,0,0,1], linewidth=0.3)# fill continents 'coral' (with zorder=0), color wet areas 'aqua'map.drawmapboundary(fill_color='white')map.fillcontinents(color='coral',lake_color='aqua')

plt.show()

I got an error:


AttributeError Traceback (most recent call last)

in () 14 # fill continents 'coral' (with zorder=0), color wet areas 'aqua' 15 map.drawmapboundary(fill_color='white') ---> 16 map.fillcontinents(color='coral',lake_color='aqua') 17 #map.drawlsmask(color="coral") 18 # shade the night areas, with alpha transparency so the ~/apps/anaconda3/envs/data-analyst-track-module-2/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py in fillcontinents(self, color, lake_color, ax, zorder, alpha) 1765 ax = ax or self._check_ax() 1766 # get axis background color. -> 1767 axisbgc = ax.get_axis_bgcolor() 1768 npoly = 0 1769 polys = [] AttributeError: 'AxesSubplot' object has no attribute 'get_axis_bgcolor' Used versions of libraries are (output of conda list, shortened): numpy 1.13.3 py36hdbf6ddf_4 basemap 1.0.7 np113py36_0 matplotlib 2.2.2 py36h0e671d2_0 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
ZelphirKaltstahl commented 6 years ago

That solved it. Thank you!