生產(chǎn)定制一個(gè)彩條標(biāo)簽。
首先導(dǎo)入:
import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import cmfrom numpy.random import randn
制作擁有垂直(默認(rèn))彩條的圖表:
fig, ax = plt.subplots()data = np.clip(randn(250, 250), -1, 1)cax = ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm)ax.set_title('Gaussian noise with vertical colorbar')# Add colorbar, make sure to specify tick locations to match desired ticklabelscbar = fig.colorbar(cax, ticks=[-1, 0, 1])cbar.ax.set_yticklabels(['< -1', '0', '> 1']) # vertically oriented colorbar效果圖:

制作擁有水平彩條的圖表:
fig, ax = plt.subplots()data = np.clip(randn(250, 250), -1, 1)cax = ax.imshow(data, interpolation='nearest', cmap=cm.afmhot)ax.set_title('Gaussian noise with horizontal colorbar')cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation='horizontal')cbar.ax.set_xticklabels(['Low', 'Medium', 'High']) # horizontal colorbarplt.show()效果圖:

腳本運(yùn)行耗時(shí):(0分0.075秒)
總結(jié)
以上就是本文關(guān)于Python matplotlib畫圖實(shí)例之繪制擁有彩條的圖表的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
| 
 
 | 
新聞熱點(diǎn)
疑難解答
圖片精選