【#文档大全网# 导语】以下是®文档大全网的小编为您整理的《【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 之间是蓝色和白色的线性
本文来源:https://www.wddqxz.cn/0253c8ab854769eae009581b6bd97f192379bf79.html