所以我有一个带有 basemap 、顶部颜色网格和设置为 cbar 的颜色条的绘图。我希望 colorbar 方向是水平的而不是垂直的,但是当我在 extend='max' 之后的 cbar=m.colorbar 行中设置 orientation='horizontal' 时,我收到以下错误:“colorbar() 有多个值关键字参数'orientation'"
有人在另一个问题上解释了为什么会发生这种情况,但老实说,我无法理解答案,也看不到有关如何修复它的解释。有人可以帮忙吗?我尝试改用 plt.colorbar,但出于某种原因它不接受我的刻度设置。
这是我之前的情节......
#Set cmap properties
bounds = np.array([0.1,0.2,0.5,1,2,3,4,6,9,13,20,30])
norm = colors.LogNorm(vmin=0.1,vmax=30) #creates logarithmic scale
#Create basemap
fig = plt.figure(figsize=(15.,10.))
m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,llcrnrlon=0,urcrnrlon=360.,lon_0=180.,resolution='c')
m.drawcoastlines(linewidth=1)
m.drawcountries(linewidth=1)
m.drawparallels(np.arange(-90,90,30.),linewidth=0.3)
m.drawmeridians(np.arange(-180.,180.,90.),linewidth=0.3)
meshlon,meshlat = np.meshgrid(lon,lat)
x,y = m(meshlon,meshlat)
#Plot variables
trend = m.pcolormesh(x,y,lintrends_36,cmap='jet', norm=norm, shading='gouraud')
#Set plot properties
plt.tight_layout()
#Colorbar
cbar=m.colorbar(trend, size='3%',ticks=bounds,extend="max") #THIS LINE
cbar.set_label(label='Linear Trend (mm/day/decade)',size=30)
cbar.set_ticklabels(bounds)
#Titles & labels
plt.suptitle('Linear Trends of Precipitation (CanESM2)',fontsize=40,y=0.962)
plt.title('a) 1979-2014',fontsize=40)
plt.ylabel('Latitude',fontsize=30)
plt.show()
map 看起来像这样。
最佳答案
你需要使用location="bottom"
cbar=m.colorbar(trend, size='3%',ticks=bounds,extend="max",location="bottom")
我从 this 得到的 basemap 文档中的示例。
关于Python-如何使颜色条方向水平?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38487440/