简体   繁体   中英

Error: x and y must have same first dimension. Why?

Why do I get the error: "x and y must have same first dimension, but have shapes (15,) and (23,)"?

index = np.where(A3_Fixed == 0)[0]

for x in index:
    A2.pop(x)
    A3_Fixed.pop(x)
    A4_Fixed.pop(x)
    A5_Fixed.pop(x)
    A6_Fixed.pop(x)
plt.plot(A2, A3_Fixed, color="brown", label="Pasta In P1", marker="o")
plt.plot(A2, A4_Fixed, color="brown", linestyle=":", label="Pasta Out P1", marker="o")
plt.plot(A2, A5_Fixed, color="green", label="Líquido de Lavagem P1", marker="o")
plt.plot(A2, A6_Fixed, color="green", label="Filtrado P1", linestyle=":", marker="o")

If A2 and A3_fixed are lists, you can ensure they are the same size by performing the following and see if your problem persists. If it does, then somehow you did not have the same number of values for your x and y , as pavel mentioned in their comment.

# limit both lists to the size of the smaller one
A2 = [:min(len(A2),len(A3_fixed))]
A3_fixed = [:min(len(A2),len(A3_fixed))]

You can also just check the lengths of each right before attempting to plot by calling print(len(list_name)) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM