Problem with plotting map using matplotlib.basemap
up vote
0
down vote
favorite
This is my Python code. It worked once but after I changed something, and I don't remember what I changed, it now returns this error:
raise RuntimeError("Can not put single artist in " RuntimeError: Can
not put single artist in more than one figure
Any help about this issue
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy.ma as ma
import netCDF4
import os
import datetime
mydate='20181110' #(put today date)
myhour = '00' # in UTC timezone
url='http://nomads.ncep.noaa.gov:9090/dods/hrrr/hrrr%s/hrrr_sfc.t%sz' %(mydate,myhour)
print url
# make sure folder exists
folder_path = 'pcptype/%s/%sz' %(mydate,myhour)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Read data
t = 10
file = netCDF4.Dataset(url)
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
time = file.variables['time'][:]
rad_ref = file.variables['refcclm'][t,:,:]
#### plotting data
m=Basemap(projection='merc',lat_ts=0,llcrnrlon=-81.0,
urcrnrlon=-66,llcrnrlat=41.0,urcrnrlat=49.0, resolution='i')
bounds_rain = [0,5,10,15,20,25,30,35,40,100]
bounds_ref = [10,25,30,35,40,100] cmap=mpl.colors.ListedColormap(['#99CCFF','#0099FF','#00FF66','#00CC00','#009900','#006600','#FFFF33','#FFCC00','#FF9900','#FF6600','#FF0000','#FF0299','#9933CC','#660099'])
xx,yy = np.meshgrid(lon,lat)
x,y =m(xx,yy)
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
norm_ref = mpl.colors.BoundaryNorm(bounds_ref, cmap.N)
first_date = datetime.datetime(1,1,1,0,0,0)
init_datetime = first_date+ datetime.timedelta(time[0])
#for t in range(1, len(time)):
print 'processing time %i ' %t
fct_datetime = first_date + datetime.timedelta(time[t])
fig_name = 'pcp_type_%s' %(fct_datetime.strftime("%Y%m%d_%H00"))
print fig_name
fig=plt.figure(figsize=(10, 10))
map1=m.contourf(x, y, rad_ref,len(bounds_ref),norm=norm_ref,cmap=cmap,levels=bounds_rain)
plt.title("RADAR | Init : %s Valid: %s"
%(init_datetime.strftime("%HZ %Y-%m-%d"),fct_datetime.strftime("%HZ %Y-%m-%d")),loc='left')
plt.savefig("%s/%s.png" %(folder_path,fig_name), dpi=200,bbox_inches='tight' )
python matplotlib-basemap
add a comment |
up vote
0
down vote
favorite
This is my Python code. It worked once but after I changed something, and I don't remember what I changed, it now returns this error:
raise RuntimeError("Can not put single artist in " RuntimeError: Can
not put single artist in more than one figure
Any help about this issue
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy.ma as ma
import netCDF4
import os
import datetime
mydate='20181110' #(put today date)
myhour = '00' # in UTC timezone
url='http://nomads.ncep.noaa.gov:9090/dods/hrrr/hrrr%s/hrrr_sfc.t%sz' %(mydate,myhour)
print url
# make sure folder exists
folder_path = 'pcptype/%s/%sz' %(mydate,myhour)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Read data
t = 10
file = netCDF4.Dataset(url)
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
time = file.variables['time'][:]
rad_ref = file.variables['refcclm'][t,:,:]
#### plotting data
m=Basemap(projection='merc',lat_ts=0,llcrnrlon=-81.0,
urcrnrlon=-66,llcrnrlat=41.0,urcrnrlat=49.0, resolution='i')
bounds_rain = [0,5,10,15,20,25,30,35,40,100]
bounds_ref = [10,25,30,35,40,100] cmap=mpl.colors.ListedColormap(['#99CCFF','#0099FF','#00FF66','#00CC00','#009900','#006600','#FFFF33','#FFCC00','#FF9900','#FF6600','#FF0000','#FF0299','#9933CC','#660099'])
xx,yy = np.meshgrid(lon,lat)
x,y =m(xx,yy)
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
norm_ref = mpl.colors.BoundaryNorm(bounds_ref, cmap.N)
first_date = datetime.datetime(1,1,1,0,0,0)
init_datetime = first_date+ datetime.timedelta(time[0])
#for t in range(1, len(time)):
print 'processing time %i ' %t
fct_datetime = first_date + datetime.timedelta(time[t])
fig_name = 'pcp_type_%s' %(fct_datetime.strftime("%Y%m%d_%H00"))
print fig_name
fig=plt.figure(figsize=(10, 10))
map1=m.contourf(x, y, rad_ref,len(bounds_ref),norm=norm_ref,cmap=cmap,levels=bounds_rain)
plt.title("RADAR | Init : %s Valid: %s"
%(init_datetime.strftime("%HZ %Y-%m-%d"),fct_datetime.strftime("%HZ %Y-%m-%d")),loc='left')
plt.savefig("%s/%s.png" %(folder_path,fig_name), dpi=200,bbox_inches='tight' )
python matplotlib-basemap
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is my Python code. It worked once but after I changed something, and I don't remember what I changed, it now returns this error:
raise RuntimeError("Can not put single artist in " RuntimeError: Can
not put single artist in more than one figure
Any help about this issue
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy.ma as ma
import netCDF4
import os
import datetime
mydate='20181110' #(put today date)
myhour = '00' # in UTC timezone
url='http://nomads.ncep.noaa.gov:9090/dods/hrrr/hrrr%s/hrrr_sfc.t%sz' %(mydate,myhour)
print url
# make sure folder exists
folder_path = 'pcptype/%s/%sz' %(mydate,myhour)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Read data
t = 10
file = netCDF4.Dataset(url)
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
time = file.variables['time'][:]
rad_ref = file.variables['refcclm'][t,:,:]
#### plotting data
m=Basemap(projection='merc',lat_ts=0,llcrnrlon=-81.0,
urcrnrlon=-66,llcrnrlat=41.0,urcrnrlat=49.0, resolution='i')
bounds_rain = [0,5,10,15,20,25,30,35,40,100]
bounds_ref = [10,25,30,35,40,100] cmap=mpl.colors.ListedColormap(['#99CCFF','#0099FF','#00FF66','#00CC00','#009900','#006600','#FFFF33','#FFCC00','#FF9900','#FF6600','#FF0000','#FF0299','#9933CC','#660099'])
xx,yy = np.meshgrid(lon,lat)
x,y =m(xx,yy)
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
norm_ref = mpl.colors.BoundaryNorm(bounds_ref, cmap.N)
first_date = datetime.datetime(1,1,1,0,0,0)
init_datetime = first_date+ datetime.timedelta(time[0])
#for t in range(1, len(time)):
print 'processing time %i ' %t
fct_datetime = first_date + datetime.timedelta(time[t])
fig_name = 'pcp_type_%s' %(fct_datetime.strftime("%Y%m%d_%H00"))
print fig_name
fig=plt.figure(figsize=(10, 10))
map1=m.contourf(x, y, rad_ref,len(bounds_ref),norm=norm_ref,cmap=cmap,levels=bounds_rain)
plt.title("RADAR | Init : %s Valid: %s"
%(init_datetime.strftime("%HZ %Y-%m-%d"),fct_datetime.strftime("%HZ %Y-%m-%d")),loc='left')
plt.savefig("%s/%s.png" %(folder_path,fig_name), dpi=200,bbox_inches='tight' )
python matplotlib-basemap
This is my Python code. It worked once but after I changed something, and I don't remember what I changed, it now returns this error:
raise RuntimeError("Can not put single artist in " RuntimeError: Can
not put single artist in more than one figure
Any help about this issue
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy.ma as ma
import netCDF4
import os
import datetime
mydate='20181110' #(put today date)
myhour = '00' # in UTC timezone
url='http://nomads.ncep.noaa.gov:9090/dods/hrrr/hrrr%s/hrrr_sfc.t%sz' %(mydate,myhour)
print url
# make sure folder exists
folder_path = 'pcptype/%s/%sz' %(mydate,myhour)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Read data
t = 10
file = netCDF4.Dataset(url)
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
time = file.variables['time'][:]
rad_ref = file.variables['refcclm'][t,:,:]
#### plotting data
m=Basemap(projection='merc',lat_ts=0,llcrnrlon=-81.0,
urcrnrlon=-66,llcrnrlat=41.0,urcrnrlat=49.0, resolution='i')
bounds_rain = [0,5,10,15,20,25,30,35,40,100]
bounds_ref = [10,25,30,35,40,100] cmap=mpl.colors.ListedColormap(['#99CCFF','#0099FF','#00FF66','#00CC00','#009900','#006600','#FFFF33','#FFCC00','#FF9900','#FF6600','#FF0000','#FF0299','#9933CC','#660099'])
xx,yy = np.meshgrid(lon,lat)
x,y =m(xx,yy)
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
norm_ref = mpl.colors.BoundaryNorm(bounds_ref, cmap.N)
first_date = datetime.datetime(1,1,1,0,0,0)
init_datetime = first_date+ datetime.timedelta(time[0])
#for t in range(1, len(time)):
print 'processing time %i ' %t
fct_datetime = first_date + datetime.timedelta(time[t])
fig_name = 'pcp_type_%s' %(fct_datetime.strftime("%Y%m%d_%H00"))
print fig_name
fig=plt.figure(figsize=(10, 10))
map1=m.contourf(x, y, rad_ref,len(bounds_ref),norm=norm_ref,cmap=cmap,levels=bounds_rain)
plt.title("RADAR | Init : %s Valid: %s"
%(init_datetime.strftime("%HZ %Y-%m-%d"),fct_datetime.strftime("%HZ %Y-%m-%d")),loc='left')
plt.savefig("%s/%s.png" %(folder_path,fig_name), dpi=200,bbox_inches='tight' )
python matplotlib-basemap
python matplotlib-basemap
edited Nov 10 at 8:38
Greenonline
96921424
96921424
asked Nov 10 at 4:24
Sami
132
132
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
The sequence of plots must be done correctly. Filled-contour is raster type, must be plotted first. Then, all the vector data can be plotted on top. Here is the snippet code that shows the plot sequence:
# ...
# Raster data must be plotted first
map1 = m.contourf(x, y, rad_ref, len(bounds_ref), norm=norm_ref, cmap=cmap,
levels=bounds_rain)
# then, these line/vector data are plotted
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
# additionally, plot useful colorbar
plt.colorbar(shrink=0.55) # draw colorbar
# ...
Resulting plot:
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The sequence of plots must be done correctly. Filled-contour is raster type, must be plotted first. Then, all the vector data can be plotted on top. Here is the snippet code that shows the plot sequence:
# ...
# Raster data must be plotted first
map1 = m.contourf(x, y, rad_ref, len(bounds_ref), norm=norm_ref, cmap=cmap,
levels=bounds_rain)
# then, these line/vector data are plotted
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
# additionally, plot useful colorbar
plt.colorbar(shrink=0.55) # draw colorbar
# ...
Resulting plot:
add a comment |
up vote
0
down vote
accepted
The sequence of plots must be done correctly. Filled-contour is raster type, must be plotted first. Then, all the vector data can be plotted on top. Here is the snippet code that shows the plot sequence:
# ...
# Raster data must be plotted first
map1 = m.contourf(x, y, rad_ref, len(bounds_ref), norm=norm_ref, cmap=cmap,
levels=bounds_rain)
# then, these line/vector data are plotted
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
# additionally, plot useful colorbar
plt.colorbar(shrink=0.55) # draw colorbar
# ...
Resulting plot:
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The sequence of plots must be done correctly. Filled-contour is raster type, must be plotted first. Then, all the vector data can be plotted on top. Here is the snippet code that shows the plot sequence:
# ...
# Raster data must be plotted first
map1 = m.contourf(x, y, rad_ref, len(bounds_ref), norm=norm_ref, cmap=cmap,
levels=bounds_rain)
# then, these line/vector data are plotted
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
# additionally, plot useful colorbar
plt.colorbar(shrink=0.55) # draw colorbar
# ...
Resulting plot:
The sequence of plots must be done correctly. Filled-contour is raster type, must be plotted first. Then, all the vector data can be plotted on top. Here is the snippet code that shows the plot sequence:
# ...
# Raster data must be plotted first
map1 = m.contourf(x, y, rad_ref, len(bounds_ref), norm=norm_ref, cmap=cmap,
levels=bounds_rain)
# then, these line/vector data are plotted
m.drawstates()
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary()
# additionally, plot useful colorbar
plt.colorbar(shrink=0.55) # draw colorbar
# ...
Resulting plot:
answered Nov 11 at 5:05
swatchai
2,58621423
2,58621423
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235979%2fproblem-with-plotting-map-using-matplotlib-basemap%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown