from random import randint
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
size = 50
A = np.array([randint(-4, 4)/10 for _ in range(size*size)])
A = (A*10 + 4)*12.5 # Translate values from [-0.4, 0.4] to [0, 100].
B = A.reshape((size, size))
ax = plt.subplot()
im = ax.imshow(B)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
im.set_clim(0, 100)
plt.colorbar(im, cax=cax)
plt.show()
1条答案
按热度按时间kknvjkwl1#
如果将数组[-0.4,0.4]的值转换为范围[0,100],就可以绘制所需的图形。
这就是我在下面的例子中所做的:
输出:x1c 0d1x