ColorMap Coding
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
add a comment |
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
add a comment |
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
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
matplotlib-basemap colormap
edited Nov 10 at 2:42
asked Nov 9 at 22:23
stratusshow
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
.
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
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
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%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
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
.
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
add a comment |
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
.
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
add a comment |
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
.
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
.
edited Nov 10 at 4:19
answered Nov 10 at 3:08
tel
6,07011430
6,07011430
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
add a comment |
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
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%2f53234039%2fcolormap-coding%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