我使用histogram2D,contourf和matplotlib從csv文件繪製密度圖。 請看看我的結果: 在matplotlib中自定義圖例的間隔
所以,我的主要要求是豪定製我的傳說的間隔,我需要有僅有5間隔0.8例如一步,當涉及到我希望它只是在用相同的顏色間隔和「2.5及以上的標記間隔> 2.5 這裏是我使用定製我的傳說代碼:
cmap = plt.cm.get_cmap('Paired', 8)
cs = m.contourf(xi, yi, g, cmap = cmap)
cbar = plt.colorbar(cs, orientation='horizontal')
cbar.set_label('la densite des impacts foudre',size=18)
# Set borders in the interval [0, 1]
bound = np.linspace(0, 1, 9)
# Preparing borders for the legend
bound_prep = np.round(bound * 7, 2)
# Creating 8 Patch instances
plt.legend([mpatches.Patch(color=cmap(b)) for b in bound[:-1]],
['{} - {}'.format(bound_prep[i], bound_prep[i+1] - 0.01) for i in range(8)], bbox_to_anchor=(1.05, 1), loc=2)
plt.gcf().set_size_inches(15,15)
plt.show()
所以基本上我需要類似的傳說到這一個:
任何想法?
我有問題,瞭解您所期望的結果。你說你想要有5個區間,但已經在代碼中有8個區間。此外,如果間隔爲0.8,則只能得到3,第八個間隔可達2.5。間隔中的顏色應該如何與等值線圖的顏色相關? – ImportanceOfBeingErnest
很明顯,你真的理解我期望的結果,所以是的,我有8個間隔,但我需要管理,以保持只有6或5間隔低於0.8的步驟,當然間隔高達2.5應該在一個總結區間稱爲2.5及以上,並具有獨特的顏色。 –