我正在尝试使用matplotlib绘制x轴上不均匀的图。但是x-tick没有显示在正确的位置。这是我上传的图片的python代码。X标记显示在图像的左下角,而不是每个数据点的下方。
import numpy as np
import matplotlib.pyplot as plt
ticks = [0.0369, 11.58, 13.41, 13.78, 15.2609, 24.9, 26.7, 61.65]
xi = list(range(len(ticks)))
rmse_before_without_cm = ([0, 5.6290, 6.5244, 7.7890, 6.0990, 11.1103, 20.1758, 30.4631])
std_error_rmse_before_without_cm = np.array([0, 0, 0, 0, 0, 0, 0, 0])
rmse_before_with_cm = np.array([0, 4.4034, 4.4712, 3.7395, 3.7687, 7.2956, 2.8387, 19.4628])
std_error_rmse_before_with_cm = np.array([0, 0, 0, 0, 0, 0, 0, 0])
X_max = 62
X_var = ticks
L = len(X_var) # number of x values
Y_var_1 = rmse_before_without_cm
Y_var_err1 = std_error_rmse_before_without_cm
Y_var_2 = rmse_before_with_cm
Y_var_err2 = std_error_rmse_before_with_cm
plt.rcParams["figure.figsize"] = [6.4, 4.8]
plt.rcParams['axes.linewidth'] = 2
plt.errorbar(X_var,Y_var_1,Y_var_err1,linestyle='None',markersize = 8,\
marker = '+', capsize = 2, color = 'magenta', label = 'RMSE Before without Joined Cloud Mask')
plt.errorbar(X_var,Y_var_2,Y_var_err2,linestyle='None',markersize = 8,\
marker = '^', capsize = 2, color = 'black', label = 'RMSE Before with Joined Cloud Mask')
FS = 18
FS2 = 16
plt.xlabel('Cloud Cover $\%$', size=FS)
plt.ylabel('RMSE', size=FS)
plt.title('RMSE vs Cloud Cover $\%$', size=FS)
plt.yticks(fontsize = FS - 2)
plt.xticks(xi, ticks)
plt.legend(fontsize = FS2-2)
plt.show()发布于 2020-10-11 22:02:13
将plt.xticks(xi, ticks)更改为plt.xticks(ticks)
您可能想格式化字体等,以获得一些可读的东西。

https://stackoverflow.com/questions/64304764
复制相似问题