例如我们用的色系是jet:
import numpy as np
import matplotlib.pylab as plt
def custom_min_max_scaling(data):
# 计算每列的最小值和最大值
min_vals = np.min(data)
max_vals = np.max(data)
# 最大最小归一化计算公式
normalized_data = (data - min_vals) / (max_vals - min_vals)
return normalized_data
if __name__ == '__main__':
data = np.random.random((100, 100, 3))
data = custom_min_max_scaling(data)
a = plt.imshow(data, cmap="jet")
ax = plt.gca()
ax.set_xticks([])
ax.set_yticks([])
plt.colorbar()
plt.show()
我们只需要在jet后面加上_r即可实现反转:
import numpy as np
import matplotlib.pylab as plt
def custom_min_max_scaling(data):
# 计算每列的最小值和最大值
min_vals = np.min(data)
max_vals = np.max(data)
# 最大最小归一化计算公式
normalized_data = (data - min_vals) / (max_vals - min_vals)
return normalized_data
if __name__ == '__main__':
data = np.random.random((100, 100, 3))
data = custom_min_max_scaling(data)
a = plt.imshow(data, cmap="jet_r")
ax = plt.gca()
ax.set_xticks([])
ax.set_yticks([])
plt.colorbar()
plt.show()