ColorMap Coding











up vote
0
down vote

favorite












I am having trouble with some coding of using a specialized colorscale and the basemap



    levels=[35,45,55,65,75,85,95,105,115]
CB_color_cycle = ['#377eb8', '#ff7f00', '#4daf4a','#f781bf', '#a65628',
'#984ea3','#999999', '#e41a1c', '#dede00']
fig=plt.figure(501)
m=Basemap(projection='merc',llcrnrlat=27,urcrnrlat=47,llcrnrlon=234,urcrnrlon=285,resolution='h')

px,py=N.meshgrid(lon+360,lat,sparse="True")
X,Y=m(px,py)


m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color='gray',alpha=0.1,lake_color='aqua')
m.drawcounties()


#plotting contours

cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')

cbar=plt.colorbar(cs)
cbar.add_lines(cs2)
cbar.ax.set_ylabel('Temp F')

plt.suptitle("SFC Temperature June 26,2017 at 19Z")
plt.show()


But I got this error although I have experience with Python, I have never had to deal with this before as I am trying to use a special color scale.



C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3608: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0.
b = ax.ishold()
C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3675: MatplotlibDeprecationWarning: axes.hold is deprecated.
See the API Changes document (http://matplotlib.org/api/api_changes.html)
for more details.
ax.hold(b)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:UsersstratusDocumentsTestforMattsPaper.py in <module>()
36 #plotting contours
37
---> 38 cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
39 cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')
40

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in with_transform(self, x, y, data, *args, **kwargs)
519 # convert lat/lon coords to map projection coords.
520 x, y = self(x,y)
--> 521 return plotfunc(self,x,y,data,*args,**kwargs)
522 return with_transform
523

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in contourf(self, x, y, data, *args, **kwargs)
3671 mask = np.logical_or(ma.getmaskarray(data),xymask)
3672 data = ma.masked_array(data,mask=mask)
-> 3673 CS = ax.contourf(x,y,data,*args,**kwargs)
3674 except:
3675 ax.hold(b)

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlib__init__.pyc in inner(ax, *args, **kwargs)
1890 warnings.warn(msg % (label_namer, func.__name__),
1891 RuntimeWarning, stacklevel=2)
-> 1892 return func(ax, *args, **kwargs)
1893 pre_doc = inner.__doc__
1894 if pre_doc is None:

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibaxes_axes.pyc in contourf(self, *args, **kwargs)
5827 self.cla()
5828 kwargs['filled'] = True
-> 5829 contours = mcontour.QuadContourSet(self, *args, **kwargs)
5830 self.autoscale_view()
5831 return contours

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in __init__(self, ax, *args, **kwargs)
862 self._transform = kwargs.get('transform', None)
863
--> 864 self._process_args(*args, **kwargs)
865 self._process_levels()
866

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _process_args(self, *args, **kwargs)
1427 self._corner_mask = mpl.rcParams['contour.corner_mask']
1428
-> 1429 x, y, z = self._contour_args(args, kwargs)
1430
1431 _mask = ma.getmask(z)

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_args(self, args, kwargs)
1518 warnings.warn('Log scale: values of z <= 0 have been masked')
1519 self.zmin = float(z.min())
-> 1520 self._contour_level_args(z, args)
1521 return (x, y, z)
1522

C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_level_args(self, z, args)
1184 warnings.warn("Contour levels are not increasing")
1185 else:
-> 1186 raise ValueError("Contour levels must be increasing")
1187
1188 def _process_levels(self):

ValueError: Contour levels must be increasing


The indenting is not the problem but rather the CB_color_cycle since I am trying to help a friend with coding for colorblindness.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am having trouble with some coding of using a specialized colorscale and the basemap



        levels=[35,45,55,65,75,85,95,105,115]
    CB_color_cycle = ['#377eb8', '#ff7f00', '#4daf4a','#f781bf', '#a65628',
    '#984ea3','#999999', '#e41a1c', '#dede00']
    fig=plt.figure(501)
    m=Basemap(projection='merc',llcrnrlat=27,urcrnrlat=47,llcrnrlon=234,urcrnrlon=285,resolution='h')

    px,py=N.meshgrid(lon+360,lat,sparse="True")
    X,Y=m(px,py)


    m.drawcoastlines()
    m.drawcountries()
    m.drawstates()
    m.fillcontinents(color='gray',alpha=0.1,lake_color='aqua')
    m.drawcounties()


    #plotting contours

    cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
    cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')

    cbar=plt.colorbar(cs)
    cbar.add_lines(cs2)
    cbar.ax.set_ylabel('Temp F')

    plt.suptitle("SFC Temperature June 26,2017 at 19Z")
    plt.show()


    But I got this error although I have experience with Python, I have never had to deal with this before as I am trying to use a special color scale.



    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3608: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0.
    b = ax.ishold()
    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3675: MatplotlibDeprecationWarning: axes.hold is deprecated.
    See the API Changes document (http://matplotlib.org/api/api_changes.html)
    for more details.
    ax.hold(b)
    ---------------------------------------------------------------------------
    ValueError Traceback (most recent call last)
    C:UsersstratusDocumentsTestforMattsPaper.py in <module>()
    36 #plotting contours
    37
    ---> 38 cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
    39 cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')
    40

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in with_transform(self, x, y, data, *args, **kwargs)
    519 # convert lat/lon coords to map projection coords.
    520 x, y = self(x,y)
    --> 521 return plotfunc(self,x,y,data,*args,**kwargs)
    522 return with_transform
    523

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in contourf(self, x, y, data, *args, **kwargs)
    3671 mask = np.logical_or(ma.getmaskarray(data),xymask)
    3672 data = ma.masked_array(data,mask=mask)
    -> 3673 CS = ax.contourf(x,y,data,*args,**kwargs)
    3674 except:
    3675 ax.hold(b)

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlib__init__.pyc in inner(ax, *args, **kwargs)
    1890 warnings.warn(msg % (label_namer, func.__name__),
    1891 RuntimeWarning, stacklevel=2)
    -> 1892 return func(ax, *args, **kwargs)
    1893 pre_doc = inner.__doc__
    1894 if pre_doc is None:

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibaxes_axes.pyc in contourf(self, *args, **kwargs)
    5827 self.cla()
    5828 kwargs['filled'] = True
    -> 5829 contours = mcontour.QuadContourSet(self, *args, **kwargs)
    5830 self.autoscale_view()
    5831 return contours

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in __init__(self, ax, *args, **kwargs)
    862 self._transform = kwargs.get('transform', None)
    863
    --> 864 self._process_args(*args, **kwargs)
    865 self._process_levels()
    866

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _process_args(self, *args, **kwargs)
    1427 self._corner_mask = mpl.rcParams['contour.corner_mask']
    1428
    -> 1429 x, y, z = self._contour_args(args, kwargs)
    1430
    1431 _mask = ma.getmask(z)

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_args(self, args, kwargs)
    1518 warnings.warn('Log scale: values of z <= 0 have been masked')
    1519 self.zmin = float(z.min())
    -> 1520 self._contour_level_args(z, args)
    1521 return (x, y, z)
    1522

    C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_level_args(self, z, args)
    1184 warnings.warn("Contour levels are not increasing")
    1185 else:
    -> 1186 raise ValueError("Contour levels must be increasing")
    1187
    1188 def _process_levels(self):

    ValueError: Contour levels must be increasing


    The indenting is not the problem but rather the CB_color_cycle since I am trying to help a friend with coding for colorblindness.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am having trouble with some coding of using a specialized colorscale and the basemap



          levels=[35,45,55,65,75,85,95,105,115]
      CB_color_cycle = ['#377eb8', '#ff7f00', '#4daf4a','#f781bf', '#a65628',
      '#984ea3','#999999', '#e41a1c', '#dede00']
      fig=plt.figure(501)
      m=Basemap(projection='merc',llcrnrlat=27,urcrnrlat=47,llcrnrlon=234,urcrnrlon=285,resolution='h')

      px,py=N.meshgrid(lon+360,lat,sparse="True")
      X,Y=m(px,py)


      m.drawcoastlines()
      m.drawcountries()
      m.drawstates()
      m.fillcontinents(color='gray',alpha=0.1,lake_color='aqua')
      m.drawcounties()


      #plotting contours

      cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
      cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')

      cbar=plt.colorbar(cs)
      cbar.add_lines(cs2)
      cbar.ax.set_ylabel('Temp F')

      plt.suptitle("SFC Temperature June 26,2017 at 19Z")
      plt.show()


      But I got this error although I have experience with Python, I have never had to deal with this before as I am trying to use a special color scale.



      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3608: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0.
      b = ax.ishold()
      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3675: MatplotlibDeprecationWarning: axes.hold is deprecated.
      See the API Changes document (http://matplotlib.org/api/api_changes.html)
      for more details.
      ax.hold(b)
      ---------------------------------------------------------------------------
      ValueError Traceback (most recent call last)
      C:UsersstratusDocumentsTestforMattsPaper.py in <module>()
      36 #plotting contours
      37
      ---> 38 cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
      39 cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')
      40

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in with_transform(self, x, y, data, *args, **kwargs)
      519 # convert lat/lon coords to map projection coords.
      520 x, y = self(x,y)
      --> 521 return plotfunc(self,x,y,data,*args,**kwargs)
      522 return with_transform
      523

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in contourf(self, x, y, data, *args, **kwargs)
      3671 mask = np.logical_or(ma.getmaskarray(data),xymask)
      3672 data = ma.masked_array(data,mask=mask)
      -> 3673 CS = ax.contourf(x,y,data,*args,**kwargs)
      3674 except:
      3675 ax.hold(b)

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlib__init__.pyc in inner(ax, *args, **kwargs)
      1890 warnings.warn(msg % (label_namer, func.__name__),
      1891 RuntimeWarning, stacklevel=2)
      -> 1892 return func(ax, *args, **kwargs)
      1893 pre_doc = inner.__doc__
      1894 if pre_doc is None:

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibaxes_axes.pyc in contourf(self, *args, **kwargs)
      5827 self.cla()
      5828 kwargs['filled'] = True
      -> 5829 contours = mcontour.QuadContourSet(self, *args, **kwargs)
      5830 self.autoscale_view()
      5831 return contours

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in __init__(self, ax, *args, **kwargs)
      862 self._transform = kwargs.get('transform', None)
      863
      --> 864 self._process_args(*args, **kwargs)
      865 self._process_levels()
      866

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _process_args(self, *args, **kwargs)
      1427 self._corner_mask = mpl.rcParams['contour.corner_mask']
      1428
      -> 1429 x, y, z = self._contour_args(args, kwargs)
      1430
      1431 _mask = ma.getmask(z)

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_args(self, args, kwargs)
      1518 warnings.warn('Log scale: values of z <= 0 have been masked')
      1519 self.zmin = float(z.min())
      -> 1520 self._contour_level_args(z, args)
      1521 return (x, y, z)
      1522

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_level_args(self, z, args)
      1184 warnings.warn("Contour levels are not increasing")
      1185 else:
      -> 1186 raise ValueError("Contour levels must be increasing")
      1187
      1188 def _process_levels(self):

      ValueError: Contour levels must be increasing


      The indenting is not the problem but rather the CB_color_cycle since I am trying to help a friend with coding for colorblindness.










      share|improve this question















      I am having trouble with some coding of using a specialized colorscale and the basemap



          levels=[35,45,55,65,75,85,95,105,115]
      CB_color_cycle = ['#377eb8', '#ff7f00', '#4daf4a','#f781bf', '#a65628',
      '#984ea3','#999999', '#e41a1c', '#dede00']
      fig=plt.figure(501)
      m=Basemap(projection='merc',llcrnrlat=27,urcrnrlat=47,llcrnrlon=234,urcrnrlon=285,resolution='h')

      px,py=N.meshgrid(lon+360,lat,sparse="True")
      X,Y=m(px,py)


      m.drawcoastlines()
      m.drawcountries()
      m.drawstates()
      m.fillcontinents(color='gray',alpha=0.1,lake_color='aqua')
      m.drawcounties()


      #plotting contours

      cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
      cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')

      cbar=plt.colorbar(cs)
      cbar.add_lines(cs2)
      cbar.ax.set_ylabel('Temp F')

      plt.suptitle("SFC Temperature June 26,2017 at 19Z")
      plt.show()


      But I got this error although I have experience with Python, I have never had to deal with this before as I am trying to use a special color scale.



      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3608: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0.
      b = ax.ishold()
      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.py:3675: MatplotlibDeprecationWarning: axes.hold is deprecated.
      See the API Changes document (http://matplotlib.org/api/api_changes.html)
      for more details.
      ax.hold(b)
      ---------------------------------------------------------------------------
      ValueError Traceback (most recent call last)
      C:UsersstratusDocumentsTestforMattsPaper.py in <module>()
      36 #plotting contours
      37
      ---> 38 cs=m.contourf(lon+360,lat,tempsfc,levels=levels,cmap=CB_color_cycle,latlon=True,extend='both')
      39 cs2=m.contour(lon+360,lat,tempsfc,levels=levels,latlon=True,colors='k',linestyles='solid')
      40

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in with_transform(self, x, y, data, *args, **kwargs)
      519 # convert lat/lon coords to map projection coords.
      520 x, y = self(x,y)
      --> 521 return plotfunc(self,x,y,data,*args,**kwargs)
      522 return with_transform
      523

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmpl_toolkitsbasemap__init__.pyc in contourf(self, x, y, data, *args, **kwargs)
      3671 mask = np.logical_or(ma.getmaskarray(data),xymask)
      3672 data = ma.masked_array(data,mask=mask)
      -> 3673 CS = ax.contourf(x,y,data,*args,**kwargs)
      3674 except:
      3675 ax.hold(b)

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlib__init__.pyc in inner(ax, *args, **kwargs)
      1890 warnings.warn(msg % (label_namer, func.__name__),
      1891 RuntimeWarning, stacklevel=2)
      -> 1892 return func(ax, *args, **kwargs)
      1893 pre_doc = inner.__doc__
      1894 if pre_doc is None:

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibaxes_axes.pyc in contourf(self, *args, **kwargs)
      5827 self.cla()
      5828 kwargs['filled'] = True
      -> 5829 contours = mcontour.QuadContourSet(self, *args, **kwargs)
      5830 self.autoscale_view()
      5831 return contours

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in __init__(self, ax, *args, **kwargs)
      862 self._transform = kwargs.get('transform', None)
      863
      --> 864 self._process_args(*args, **kwargs)
      865 self._process_levels()
      866

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _process_args(self, *args, **kwargs)
      1427 self._corner_mask = mpl.rcParams['contour.corner_mask']
      1428
      -> 1429 x, y, z = self._contour_args(args, kwargs)
      1430
      1431 _mask = ma.getmask(z)

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_args(self, args, kwargs)
      1518 warnings.warn('Log scale: values of z <= 0 have been masked')
      1519 self.zmin = float(z.min())
      -> 1520 self._contour_level_args(z, args)
      1521 return (x, y, z)
      1522

      C:UsersstratusAppDataLocalEnthoughtCanopyUserlibsite-packagesmatplotlibcontour.pyc in _contour_level_args(self, z, args)
      1184 warnings.warn("Contour levels are not increasing")
      1185 else:
      -> 1186 raise ValueError("Contour levels must be increasing")
      1187
      1188 def _process_levels(self):

      ValueError: Contour levels must be increasing


      The indenting is not the problem but rather the CB_color_cycle since I am trying to help a friend with coding for colorblindness.







      matplotlib-basemap colormap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 2:42

























      asked Nov 9 at 22:23









      stratusshow

      32




      32
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          CB_color_cycle is just a list of colors, so use the colors keyword instead of cmap:



          cs = m.contourf(lon+360, lat, tempsfc, levels=levels, colors=CB_color_cycle, latlon=True, extend='both')


          Here's what it says about the colors keyword in the contourf docs:




          colors : color string or sequence of colors, optional
          The colors of the levels, i.e. the lines for contour and the areas for contourf.



          The sequence is cycled for the levels in ascending order. If the sequence is shorter than the number of levels, it's repeated.



          As a shortcut, single color strings may be used in place of one-element lists, i.e. 'red' instead of ['red'] to color all levels with the same color. This shortcut does only work for color strings, not for other ways of specifying colors.



          By default (value None), the colormap specified by cmap will be used.




          If you were actually trying to do something fancier involving a real ColorMap, see the documentation for ListedColorMap or LinearSegmentedColormap (and maybe also this SO answer) for details on converting a list of colors into a proper ColorMap.






          share|improve this answer























          • I’ll try it when I get back on
            – stratusshow
            Nov 10 at 3:23










          • It works but it gives me an awkward color scale though.
            – stratusshow
            Nov 10 at 22:00











          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%2f53234039%2fcolormap-coding%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










          CB_color_cycle is just a list of colors, so use the colors keyword instead of cmap:



          cs = m.contourf(lon+360, lat, tempsfc, levels=levels, colors=CB_color_cycle, latlon=True, extend='both')


          Here's what it says about the colors keyword in the contourf docs:




          colors : color string or sequence of colors, optional
          The colors of the levels, i.e. the lines for contour and the areas for contourf.



          The sequence is cycled for the levels in ascending order. If the sequence is shorter than the number of levels, it's repeated.



          As a shortcut, single color strings may be used in place of one-element lists, i.e. 'red' instead of ['red'] to color all levels with the same color. This shortcut does only work for color strings, not for other ways of specifying colors.



          By default (value None), the colormap specified by cmap will be used.




          If you were actually trying to do something fancier involving a real ColorMap, see the documentation for ListedColorMap or LinearSegmentedColormap (and maybe also this SO answer) for details on converting a list of colors into a proper ColorMap.






          share|improve this answer























          • I’ll try it when I get back on
            – stratusshow
            Nov 10 at 3:23










          • It works but it gives me an awkward color scale though.
            – stratusshow
            Nov 10 at 22:00















          up vote
          0
          down vote



          accepted










          CB_color_cycle is just a list of colors, so use the colors keyword instead of cmap:



          cs = m.contourf(lon+360, lat, tempsfc, levels=levels, colors=CB_color_cycle, latlon=True, extend='both')


          Here's what it says about the colors keyword in the contourf docs:




          colors : color string or sequence of colors, optional
          The colors of the levels, i.e. the lines for contour and the areas for contourf.



          The sequence is cycled for the levels in ascending order. If the sequence is shorter than the number of levels, it's repeated.



          As a shortcut, single color strings may be used in place of one-element lists, i.e. 'red' instead of ['red'] to color all levels with the same color. This shortcut does only work for color strings, not for other ways of specifying colors.



          By default (value None), the colormap specified by cmap will be used.




          If you were actually trying to do something fancier involving a real ColorMap, see the documentation for ListedColorMap or LinearSegmentedColormap (and maybe also this SO answer) for details on converting a list of colors into a proper ColorMap.






          share|improve this answer























          • I’ll try it when I get back on
            – stratusshow
            Nov 10 at 3:23










          • It works but it gives me an awkward color scale though.
            – stratusshow
            Nov 10 at 22:00













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          CB_color_cycle is just a list of colors, so use the colors keyword instead of cmap:



          cs = m.contourf(lon+360, lat, tempsfc, levels=levels, colors=CB_color_cycle, latlon=True, extend='both')


          Here's what it says about the colors keyword in the contourf docs:




          colors : color string or sequence of colors, optional
          The colors of the levels, i.e. the lines for contour and the areas for contourf.



          The sequence is cycled for the levels in ascending order. If the sequence is shorter than the number of levels, it's repeated.



          As a shortcut, single color strings may be used in place of one-element lists, i.e. 'red' instead of ['red'] to color all levels with the same color. This shortcut does only work for color strings, not for other ways of specifying colors.



          By default (value None), the colormap specified by cmap will be used.




          If you were actually trying to do something fancier involving a real ColorMap, see the documentation for ListedColorMap or LinearSegmentedColormap (and maybe also this SO answer) for details on converting a list of colors into a proper ColorMap.






          share|improve this answer














          CB_color_cycle is just a list of colors, so use the colors keyword instead of cmap:



          cs = m.contourf(lon+360, lat, tempsfc, levels=levels, colors=CB_color_cycle, latlon=True, extend='both')


          Here's what it says about the colors keyword in the contourf docs:




          colors : color string or sequence of colors, optional
          The colors of the levels, i.e. the lines for contour and the areas for contourf.



          The sequence is cycled for the levels in ascending order. If the sequence is shorter than the number of levels, it's repeated.



          As a shortcut, single color strings may be used in place of one-element lists, i.e. 'red' instead of ['red'] to color all levels with the same color. This shortcut does only work for color strings, not for other ways of specifying colors.



          By default (value None), the colormap specified by cmap will be used.




          If you were actually trying to do something fancier involving a real ColorMap, see the documentation for ListedColorMap or LinearSegmentedColormap (and maybe also this SO answer) for details on converting a list of colors into a proper ColorMap.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 4:19

























          answered Nov 10 at 3:08









          tel

          5,10211429




          5,10211429












          • I’ll try it when I get back on
            – stratusshow
            Nov 10 at 3:23










          • It works but it gives me an awkward color scale though.
            – stratusshow
            Nov 10 at 22:00


















          • I’ll try it when I get back on
            – stratusshow
            Nov 10 at 3:23










          • It works but it gives me an awkward color scale though.
            – stratusshow
            Nov 10 at 22:00
















          I’ll try it when I get back on
          – stratusshow
          Nov 10 at 3:23




          I’ll try it when I get back on
          – stratusshow
          Nov 10 at 3:23












          It works but it gives me an awkward color scale though.
          – stratusshow
          Nov 10 at 22:00




          It works but it gives me an awkward color scale though.
          – stratusshow
          Nov 10 at 22:00


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234039%2fcolormap-coding%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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()