【发布时间】:2020-10-13 08:55:32
【问题描述】:
我目前正在尝试创建一个颜色图。但是,我有一个问题,即颜色图颜色和颜色条颜色不同。如何更改颜色条颜色方案,使其与地图的“hot_r”颜色方案相匹配?
代码如下:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
from scipy.interpolate import interp2d
x_list = np.array(X_COORDINATE)
z_list = np.array(Z_COORDINATE)
C_I_list = np.array(C_I)
# f will be a function with two arguments (x and z coordinates),
# but those can be array_like structures too, in which case the
# result will be a matrix representing the values in the grid
# specified by those arguments
f = interp2d(x_list,z_list,C_I_list,kind="linear")
x_coords = np.arange(min(x_list),max(x_list)+1)
z_coords = np.arange(min(z_list),max(z_list)+1)
c_i = f(x_coords,z_coords)
fig = plt.imshow(c_i,
extent=[min(x_list),max(x_list),min(z_list),max(z_list)],
origin="lower", interpolation='spline16', cmap='hot_r')
x_for_horizontal_line = [0,1]
y_for_horizontal_line = [1,1]
x_for_vertical_line = [1,1]
y_for_vertical_line = [0,1]
# Show the positions of the sample points, just to have some reference
fig.axes.set_autoscale_on(False)
plt.scatter(x_list,z_list,400,facecolors='none')
plt.plot(x_for_horizontal_line, y_for_horizontal_line, color='w')
plt.plot(x_for_vertical_line, y_for_vertical_line, color='w')
plt.xlim(left=1,right=5)
plt.xlabel('NF Fracture Center, x (m)')
plt.ylabel('NF Fracture Center, z (m)')
plt.title('C I')
plt.colorbar()
plt.show()
生成的地图和颜色条如下所示(请注意,我无法显示实际数据,因此会出现奇怪的裁剪图像):
【问题讨论】:
标签: python plot graph colorbar colormap