python - How do i change the number of ticks? -
so i've been searching on se while , nothing find works ..... have dataframe of min , max temperatures on years.
plt.figure() plt.gca().fill_between(range(len(tmin)), tmin, tmax, facecolor='blue', alpha=0.25) plt.plot(range(365), tmin, 'b', range(365), tmax, 'r') plt.locator_params(axis = 'x', nbins = 12) x = plt.gca().xaxis m = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] ax = plt.gca() ax.locator_params(axis = 'x', nbins = 12) ax.set_xticklabels(m) ax.set_ylabel('t(c)') ax.set_title('temperature') plt.xlim([0,365]) # ax.set_xticks(np.linspace(0,1,12)) plt.show() it still outputs same number of ticks in original plot, x-axis [0, 50, 100, ..., 350]
you can set ticks manually getting days since jan 1 each month.
import datetime dt import numpy np import matplotlib.pyplot plt x = np.arange(365) y = 100 + 250*np.sin(9*(x-50)/720) + 80*np.random.rand(365) m = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] # start day each month index ticks = [(dt.date(2016,m,1)-d0).days m in range(1,13)] fig,ax = plt.subplots(1,1) ax.plot(x,y) ax.set_xticks(ticks) ax.set_xticklabels(m) ax.set_xlim(-3,365) plt.show() 

Comments
Post a Comment