国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

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

瀏覽:2日期: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)過歸一化的df_int = pd.DataFrame(, columns=variables_int, index=labels_int)

接下來就是畫圖了:

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’)

可以通過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)文章:
主站蜘蛛池模板: 宜春市| 阳山县| 开阳县| 黄大仙区| 乐陵市| 浦江县| 湖州市| 广昌县| 基隆市| 永年县| 灌云县| 普格县| 左权县| 建德市| 德庆县| 正镶白旗| 兴义市| 台中市| 元朗区| 庆阳市| 定州市| 包头市| 灵丘县| 滦平县| 奉贤区| 吉林市| 吉木萨尔县| 名山县| 呼图壁县| 曲靖市| 越西县| 浦城县| 德惠市| 松潘县| 贡觉县| 麻城市| 沅江市| 云阳县| 阿克陶县| 恭城| 平凉市|