Într-o figură matplotlib, cum pot face ca dimensiunea fontului pentru etichetele de bifurcație folosind ax1.set_xticklabels()
să fie mai mică?
Mai mult, cum se poate roti de pe orizontală pe verticală?
De fapt, există o modalitate mai simplă. Tocmai am găsit:
import matplotlib.pyplot as plt
# We prepare the plot
fig, ax = plt.subplots()
# We change the fontsize of minor ticks label
ax.tick_params(axis='both', which='major', labelsize=10)
ax.tick_params(axis='both', which='minor', labelsize=8)
Totuși, aceasta răspunde doar la partea de dimensiune a label
din întrebarea ta.
Vă rugăm să rețineți că versiunile mai noi ale MPL au o comandă rapidă pentru această sarcină. Un exemplu este prezentat în celălalt răspuns la această întrebare: https://stackoverflow.com/a/11386056/42346
Codul de mai jos este în scop ilustrativ și nu este neapărat optimizat.
import matplotlib.pyplot as plt
import numpy as np
def xticklabels_example():
fig = plt.figure()
x = np.arange(20)
y1 = np.cos(x)
y2 = (x**2)
y3 = (x**3)
yn = (y1,y2,y3)
COLORS = ('b','g','k')
for i,y in enumerate(yn):
ax = fig.add_subplot(len(yn),1,i+1)
ax.plot(x, y, ls='solid', color=COLORS[i])
if i != len(yn) - 1:
# all but last
ax.set_xticklabels( () )
else:
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(14)
# specify integer or one of preset strings, e.g.
#tick.label.set_fontsize('x-small')
tick.label.set_rotation('vertical')
fig.suptitle('Matplotlib xticklabels Example')
plt.show()
if __name__ == '__main__':
xticklabels_example()