python colorbar非线性映射_【IT专家】在python中使用matplotlib制作自定义色彩映射

本文由我司收集整编,推荐下载,如有疑问,请与我司联系

python

中使用

matplotlib

制作自定义色彩映射

python

中使用

matplotlib

制作自定义色彩映射

[

]Making

a

custom

colormap

using matplotlib in python I have an image that

I’m

showing with matplotlib.

我有一个我用

matplotlib

显示的图像。

The image is generated by the following code:

该图像由以下代码生成:

import numpy as npimport matplotlib.pyplot as pltfrom matplotlib import cm [[ 0.000,

0.120,

0.043,

0.094,

0.037,

0.045],

[

0.120,

0.000,

0.108,

0.107,

0.105,

0.108],

[

0.043,

0.108,

0.000,

0.083,

0.043,

0.042],

[

0.094,

0.107,

0.083,

0.000,

0.083,

0.089],

[

0.037,

0.105,

0.043,

0.083,

0.000,

2.440],

[

0.045,

0.108,

0.042,

0.089,

2.440,

0.000]])mask

=

np.tri(data.shape[0],

k=-1)data

=

np.ma.array(data,

mask=mask)

#

Mask

out

the

lower

triangle

of

data.fig,

ax

=

plt.subplots(sharex=True)im

=

ax.pcolor(data,

edgecolors=‘black’,

linewidths=0.3)#

Formatfig

=

plt.gcf()fig.set_size_inches(10,

10)ax.set_yticks(np.arange(data.shape[0])

+

0.5,

minor=False)ax.set_xticks(np.arange(data.shape[1])

+

0.5,

minor=False)#

Turn

off

the

frame.ax.set_frame_on(False)ax.set_aspect(‘equal’)

#

Ensure

heatmap

cells

are

square.#

Want

a

more

natural,

table-like

display.ax.invert_yaxis()ax.yaxis.tick_right()ax.xaxis.tick_top()ax.set_xticklabels(labels,

minor=False)ax.set_yticklabels(labels,

minor=False)#

Rotate

the

upper

labels.plt.xticks(rotation=90)ax.grid(False)ax = plt.gca()for t in ax.xaxis.get_major_ticks():

t.tick1On

= False

t.tick2On

=

Falsefor

t

in

ax.yaxis.get_major_ticks():

t.tick1On =

False

t.tick2On

=

Falsefig.colorbar(im)fig.savefig(‘out.png’,

transparent=False,

bbox_inches=‘tight’,

pad_inches=0)

I’d

like to apply a custom colormap so that values:

我想应用自定义色图,以便值:

between 0-1 are linear gradient from blue and white 0-1

之间是蓝色和白色的线性

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值