在具有离散间隔的轮廓图中使用extend
在具有离散级别的轮廓图中使用扩展时,颜色栏中不会出现一种颜色。此外,最后两个间隔重复相同的颜色。
我的代码就像
from mpl_toolkits.basemap import Basemap, cm
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors
nlat=np.arange(-40,40.1,0.25)
nlon=np.arange(30,120.1,0.25)
x,y = np.meshgrid(nlon,nlat)
m = Basemap(projection='cyl',llcrnrlat=-40,urcrnrlat=40,llcrnrlon=30,urcrnrlon=120)
clevs = np.array([0,1,2,5,10,20,50,80])
val=np.random.randint(1, 150, size=(321, 361))
colors=['white','yellow', 'lightgreen', 'green','lightskyblue', 'blue','coral', 'red']
cm = matplotlib.colors.ListedColormap(colors)
norm = matplotlib.colors.BoundaryNorm(clevs,len(clevs))
cs = m.contourf(x,y,val,clevs,cmap=cm,norm=norm,latlon=True,extend='max')
parallels = np.arange(-60.,61,10.)
m.drawparallels(parallels,labels=[True,False,True,False],fontsize=7,linewidth=0)
meridians = np.arange(-180.,180.,10.)
m.drawmeridians(meridians,labels=[False,False,False,True],fontsize=7,linewidth=0)
cbar = m.colorbar(cs,location='right',pad="5%")
plt.show()
此处,珊瑚色未出现在颜色栏中,红色以 50-80 和 >80 的间隔重复。如何解决这个问题?
While using extend in contourf plot with discrete levels, one color is not appearing in the colorbar. Also, same color is repeating for last two intervals.
My code is like
from mpl_toolkits.basemap import Basemap, cm
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors
nlat=np.arange(-40,40.1,0.25)
nlon=np.arange(30,120.1,0.25)
x,y = np.meshgrid(nlon,nlat)
m = Basemap(projection='cyl',llcrnrlat=-40,urcrnrlat=40,llcrnrlon=30,urcrnrlon=120)
clevs = np.array([0,1,2,5,10,20,50,80])
val=np.random.randint(1, 150, size=(321, 361))
colors=['white','yellow', 'lightgreen', 'green','lightskyblue', 'blue','coral', 'red']
cm = matplotlib.colors.ListedColormap(colors)
norm = matplotlib.colors.BoundaryNorm(clevs,len(clevs))
cs = m.contourf(x,y,val,clevs,cmap=cm,norm=norm,latlon=True,extend='max')
parallels = np.arange(-60.,61,10.)
m.drawparallels(parallels,labels=[True,False,True,False],fontsize=7,linewidth=0)
meridians = np.arange(-180.,180.,10.)
m.drawmeridians(meridians,labels=[False,False,False,True],fontsize=7,linewidth=0)
cbar = m.colorbar(cs,location='right',pad="5%")
plt.show()
Here, coral color is not appearing in the colorbar and red color is repeating for 50-80 and >80 intervals. How to solve this issue ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你必须告诉 BoundaryNorm< /a> 以及您期望值高于限制:
You have to tell BoundaryNorm as well that you expect values above the limit: