Do the values in plt.axis() always have to be in increasing order?


#1

Question

In the context of this exercise, do the values in plt.axis() always have to be in increasing order, as in plt.axis([min_x, max_x, min_y, max_y])?

Answer

No, we can actually set the values for the axis to be in decreasing order as well.

If we take the example plot in the exercise, say that instead of setting the axis to this:
plt.axis([0, 3, 2, 5])

we instead set it to these values, with both the x and y min and max values reversed:
plt.axis([3, 0, 5, 2])

What this will do is not throw an error, but instead the graph will be essentially drawn inverted, both on the x axis and the y axis. The x axis will be for x values from 3 to 0, and the y axis will be for values 5 to 2, both in decreasing order.

As a result, you have the option, if ever needed, to draw the graph with axes in reverse or decreasing order, which is a nice feature to have.