久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

瀏覽:3日期:2022-07-03 08:13:14

python matplotlib畫圖使用colorbar工具自定義顏色 colorbar(draw colorbar without any mapple/plot)

自定義colorbar可以畫出任何自己想要的colorbar,自由自在、不受約束,不依賴于任何已有的圖(plot/mappable)。這里使用的是mpl.colorbar.ColorbarBase類,而colorbar類必須依賴于已有的圖。

參數(shù)可以參考下面的描述->matplotlib:

class matplotlib.colorbar.ColorbarBase(ax, cmap=None, norm=None, alpha=None, values=None, boundaries=None, orientation=‘vertical’, ticklocation=‘a(chǎn)uto’, extend=‘neither’, spacing=‘uniform’, ticks=None, format=None, drawedges=False, filled=True, extendfrac=None, extendrect=False, label=’’)[source]

參數(shù)簡(jiǎn)單描述

ax :可用于設(shè)置colorbar的位置、長(zhǎng)、寬 norm :用于規(guī)范化?設(shè)置顏色條最大最小值 cmap:顏色(可參考本篇博文的最后部分——推薦色帶與自定義色帶) boundaries:要想使用extend,在norm之外,必須要有兩個(gè)額外的boundaries orientation:colorbar方向,躺平or垂直 extend:延伸方向(在norm之外colorbar可延伸) ticks:自定義各段的tick(記號(hào))給一個(gè)例子,首先定義一下橫縱坐標(biāo)的名稱,以及df_int:

給一個(gè)例子,首先定義一下橫縱坐標(biāo)的名稱,以及df_int:

labels_int = [’A’, ’B’, ’C’, ’D’]variables_int = [’A’, ’B’, ’C’, ’D’]# x_normed_int 可以是一個(gè)4*4的數(shù)組,經(jīng)過(guò)歸一化的df_int = pd.DataFrame(, columns=variables_int, index=labels_int)

接下來(lái)就是畫圖了:

fig = plt.figure() ax = fig.add_subplot(111) cax = ax.matshow(df, interpolation=’nearest’, cmap=’GnBu’) fig.colorbar(cax) tick_spacing = 1 ax.xaxis.set_major_locator(ticker.MultipleLocator(tick_spacing)) ax.yaxis.set_major_locator(ticker.MultipleLocator(tick_spacing)) ax.set_xticklabels([’’] + list(df.columns)) ax.set_yticklabels([’’] + list(df.index)) plt.show()

其中:

cax = ax.matshow(df, interpolation=’nearest’, cmap=’GnBu’)

可以通過(guò)cmap修改,得到不同的顏色帶

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

最終可以看到結(jié)果如下圖:

python可視化 matplotlib畫圖使用colorbar工具自定義顏色

到此這篇關(guān)于python可視化 matplotlib畫圖使用colorbar工具自定義顏色的文章就介紹到這了,更多相關(guān)python colorbar自定義顏色內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 连城县| 米泉市| 黄山市| 昌黎县| 建阳市| 响水县| 长子县| 辉南县| 伽师县| 西林县| 宜章县| 高阳县| 阳东县| 南丹县| 海淀区| 安宁市| 扎兰屯市| 贡觉县| 南宫市| 青田县| 郧西县| 迭部县| 宁河县| 砀山县| 德清县| 青岛市| 荆门市| 广东省| 乡宁县| 兴和县| 塔河县| 邯郸市| 仲巴县| 利川市| 舞阳县| 共和县| 城口县| 东阳市| 志丹县| 东乡县| 周至县|