python - Matplotilb bar chart: diagonal tick labels -
i plotting bar chart in python using matplotlib.pyplot
. chart contain large number of bars, , each bar has own label. thus, labels overlap, , no more readable. label displayed diagonally not overlab, such in this image.
this code:
import matplotlib.pyplot plt n =100 menmeans = range(n) ind = range(n) ticks = ind fig = plt.figure() ax = fig.add_subplot(111) rects1 = ax.bar(ind, menmeans, align = 'center') ax.set_xticks(ind) ax.set_xticklabels( range(n) ) plt.show()
how can labels displayed diagonally?
the example in documents uses:
plt.setp(xticknames, rotation=45, fontsize=8)
so in case think: ax.set_ticklabels(range(n), rotation=45, fontsize=8)
give angle still overlap. try:
import matplotlib.pyplot plt n =100 menmeans = range(n) ind = range(n) ticks = ind fig = plt.figure() ax = fig.add_subplot(111) rects1 = ax.bar(ind, menmeans, align = 'center') ax.set_xticks(range(0,n,10)) ax.set_xticklabels( range(0,n,10), rotation=45 ) plt.show()
Comments
Post a Comment