Ryan's Blog

Matplotlib: axis labels, rotating and aligning

Posted in Uncategorized by ryanlayer on December 17, 2013
n=5

x = np.arange(n)
y = np.sin(np.linspace(-3,3,n))
xlabels = ['Ticklabel %i' % i for i in range(n)]

fig, axs = plt.subplots(1,3, figsize=(12,3))

ha = ['right', 'center', 'left']

for n, ax in enumerate(axs):
    ax.plot(x,y, 'o-')
    ax.set_title(ha[n])
    ax.set_xticks(x)
    ax.set_xticklabels(xlabels, rotation=40, ha=ha[n])

 

http://stackoverflow.com/questions/14852821/aligning-rotated-xticklabels-with-their-respective-xticks

Tagged with: , ,