Restore default titles of matplotlib axis

My question is how can I restore matplotlib axis captions to default after changing them. For example, in the code below, I built squares of numbers from 1 to 9, and then changed yticks to [20, 40, 60]. By default, the yticks for this graph were [0, 10, 20, 30, 40, 50, 60, 70, 80] before I changed them. So, from now on, how can I return these yticks to default?

import matplotlib.pyplot as plt import numpy as np x = np.arange(9) + 1 y = x ** 2 fig, ax1 = plt.subplots() ax1.plot(x, y) ax1.set_yticks([20, 40, 60]) plt.show() 
+7
source share
1 answer

I found the answer to my question. As indicated in the matplotlib documentation, AutoLocator is the default tick locator for most charts. To enable AutoLocator, look at the edited version of my script below.

 import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import AutoLocator x = np.arange(9) + 1 y = x ** 2 fig, ax1 = plt.subplots() ax1.plot(x, y) ax1.set_yticks([20, 40, 60]) ax1.yaxis.set_major_locator(AutoLocator()) # solution plt.show() 
+3
source

Source: https://habr.com/ru/post/1265220/


All Articles