直接平滑显示:
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
x = np.array([2,4,6,8,10])
y = np.array([1,2,3,4])
z = np.array([[95,95,95,95,95],
[80,80,80,80,80],
[70,70,70,70,70],
[100,100,100,100,100]])
fig, axe = plt.subplots()
ax0 = axe.imshow(z, origin="lower", cmap="viridis_r", interpolation='bicubic')
plt.colorbar(ax0)
plt.show()
插值且平滑显示:
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
x = np.array([2,4,6,8,10])
y = np.array([1,2,3,4])
z = np.array([[95,95,95,95,95],
[80,80,80,80,80],
[70,70,70,70,70],
[100,100,100,100,100]])
interpolant = interpolate.interp2d(x, y, z.ravel(), kind="linear")
xlin = np.linspace(0, 10, 100)
ylin = np.linspace(0, 10, 100)
zhat = interpolant(xlin, ylin)
fig, axe = plt.subplots()
ax1 = axe.imshow(zhat.T, origin="lower", cmap="jet", interpolation='bicubic')
plt.colorbar(ax1)
ticks_x = np.linspace((100/5)/2,100-(100/5)/2,5)
ticks_y = np.linspace((100/4)/2,100-(100/4)/2,4)
plt.xticks(ticks=ticks_x, labels=[2,4,6,8,10])
plt.yticks(ticks=ticks_y, labels=[1,2,3,4])
plt.show()
使用热力图显示:
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
x = np.array(([2, 4, 6, 8, 10]))
y = np.array(([1, 2, 3, 4]))
x_r, y_r = np.meshgrid(x, y)
z = np.array([[95, 95, 95, 95, 95],
[80, 80, 80, 80, 80],
[70, 70, 70, 70, 70],
[100, 100, 100, 100, 100]])
c = plt.pcolormesh(x_r, y_r, z, cmap='jet', shading='gouraud')# 彩虹热力图
# c = plt.pcolormesh(x_r, y_r, z, cmap='viridis_r')# 普通热力图
plt.colorbar(c, label='AUPR')
plt.xlabel('x')
plt.ylabel('y')
plt.show()