[英]Python- How to make colorbar orientation horizontal?
所以我有一個帶有底圖的繪圖,頂部有一個顏色網格,以及一個設置為 cbar 的顏色條。 我希望顏色條的方向是水平的而不是垂直的,但是當我在 extend='max' 之后的 cbar=m.colorbar 行中設置orientation='horizontal' 時,我收到以下錯誤:“colorbar() got multiple values for關鍵字參數'方向'"
有人在另一個問題上解釋了為什么會發生這種情況,但老實說,我無法理解答案或看到如何解決它的解釋。 有人可以幫忙嗎? 我嘗試使用 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()
地圖看起來像這樣。
正如其他人在評論中已經指出的那樣
plt.colorbar(orientation='horizontal')
是一種替代(更簡單)的解決方案!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.