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' )









share|improve this question




























    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' )









    share|improve this question


























      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' )









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 8:38









      Greenonline

      96521424




      96521424










      asked Nov 10 at 4:24









      Sami

      132




      132
























          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:



          enter image description here






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            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

























            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:



            enter image description here






            share|improve this answer

























              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:



              enter image description here






              share|improve this answer























                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:



                enter image description here






                share|improve this answer












                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:



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 5:05









                swatchai

                2,51121423




                2,51121423






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine