I’ve noticed a change in the order of arguments when using the ax.plot() function in Matplotlib.
In a previous example, the output values (let’s call them squares) were positioned before any other argument, and I thought it was being called positionally, like this:
squares = [1, 4, 9, 16, 25]
ax.plot(squares, linewidth=3)
However, as I was learning how to specify the input values for the squares, my book showed the argument for input values positioned before the output values, like this:
input_values = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]
ax.plot(input_values, squares, linewidth=3)
I was expecting to see this instead:
ax.plot(squares, input_values, linewidth=3) # Not a keyword argument, so why is Matplotlib expecting the input values argument first?
Or, because the input values start from 0 by default, I was expecting something like this:
ax.plot(squares, some_parameter_names=some_default_value, linewidth=3)
Maybe there is some parameter syntax that I am not aware of?
If the input values parameter has positional priority to the output values, how does Matplotlib know that my argument is intended to specify the output values when I only specify the output values and don’t specify the input values?"
Is there a lesson I missed?
Sure, I read that plot() is defaulting 0 as the first tick mark label for the x axis if only a series of values is fed into the function and that if the input values need be specified, the plot() function expects the first argument to be the input values when two series are specified. But how can it work like that?