ValueError:x 和 y 必须具有相同的第一维度,但具有形状 (21,) 和 (22,)

问题描述 投票:0回答:1

我正在尝试从数组制作图形,但结果一直显示值错误,我该怎么办?

这是我的代码:

# array bisection
array_list_iter_bisect = np.array(list_iter_bisect)
array_list_ea_bisect = np.array(list_ea_bisect)

# array false position
array_list_iter_falsepost = np.array(list_iter_falsepost)
array_list_ea_falsepost = np.array(list_ea_falsepost)

iter_max = 0
matrix_iter_count = [array_list_ea_bisect,array_list_iter_falsepost]
for arr_iter in matrix_iter_count:
    if (iter_max < arr_iter[-1]):
        iter_max = arr_iter[-1]

# Parameter for the constant function of Error Max
error_max = es
x_error_max = range(1, iter_max+1)
y_error_max = [error_max] * len(x_error_max)

# Plotting the graph 
plt.plot(list_iter_bisect, list_ea_bisect, c='blue')
plt.plot(list_iter_falsepost, list_ea_falsepost, c='green')
plt.plot(x_error_max, y_error_max, c='black')
plt.plot(x_error_max, y_error_max, c='black')
plt.annotate('εs', xy=(0, error_max), xytext=(-1, error_max), fontsize=12)
plt.xlabel('Iteration #')
plt.ylabel('εa (error)')
plt.title(f'εa method vs iteration Z-factor | T = {660}R | P = {3000} psia')
plt.legend(["Bisection", "False-Position"], bbox_to_anchor=(0.75, 1.15), ncol=2)

plt.grid(True)
plt.show()

我应该弹出数组吗?

arrays graphics
1个回答
0
投票

不知道发生错误的行,也不知道list_iter_bisect、list_ea_bisect、list_iter_falsepost、list_ea_falsepost的内容/大小,就是

我认为错误可能在这里:

plt.plot(x_error_max, y_error_max, c='black')

其中包含定义:

x_error_max = range(1, iter_max+1)
y_error_max = [error_max] * len(x_error_max)

尝试通过以下方式定义x_error_max:

x_error_max = np.arange(1, iter_max+1)

都可以

x_error_max = range(1, iter_max)

我建议不要重复这句话:

plt.plot(x_error_max, y_error_max, c='black')

两次

© www.soinside.com 2019 - 2024. All rights reserved.