What if the number of x values doesn't match the number of y values?


#1

Question

In Matplotlib, what if the number of x values doesn’t match the number of y values for our plot?

Answer

If the two values do not match dimensions, then this will usually end up in an error, and the graph not showing.

The dimensions of the x values must match the dimensions of the y values, meaning that they must have the same number of values passed in.

If using the Numpy library, you can obtain the shape of an Array using the .shape property.

Items = np.array([1, 2, 3, 4, 5])
Items.shape # (5, ) - which means a 1D array of 5 elements