Open oldoc63 opened 1 year ago
We can also modify the y-ticks by using ax.set_yticks().
When we change the x-ticks, their labels automatically change to match. But, if we want special labels (such as strings), we can use the command ax.set_xticklabels() or ax.set_yticklabels(). For example, we might want to have a y-axis with ticks at 0.1, 0.6, and 0.8, but label them 10%, 60% and 80%, respectively.
In all of our previous exercises, our commands have started with plt.. In order to modify tick marks, we'll have to try something a little bit different. Because our plots can have multiple subplots, we have to specify which one we want to modify, In order to do that, we call plt.subplot() in a different way:
ax = plt.subplot(1,1,1)
ax
is an axes object, and it lets us modify the axes belonging to a specific subplot. Even if we only have one subplot, when we want to modify the ticks, we will need to start by calling either ax = plt.subplot(1,1,1) or ax = plt.subplot() in order to get our axes object.Suppose we wanted to set our x-ticks to be at 1, 2 and 4.