python - Formatting string ticklabels matplotlib -


i have set of ticklabels strings on x axis, , want able -> modify -> set them. example have plot looks this:

import matplotlib.pyplot plt  fig, ax = plt.subplots() ax.plot(range(1,6), range(5)) plt.xticks(range(1,6), ['a','b','c','d','e'] 

and want change labels on x axis ['(a)','(b)','(c)','(d)','(e)']

what simplest/best way this? i've tried things like:

labels = ['(%s)' % l l in ax.xaxis.get_ticklabels()] ax.xaxis.set_ticklabels(labels) 

but ax.xaxis.get_ticklabels() returns matplotlib text objects opposed list of strings , i'm not sure how go modifying them. tried using matplotlib.ticker.funcformatter hold of numeric positions not labels themselves. appreciated.

one more layer unpeel:

import matplotlib.pyplot plt  fig, ax = plt.subplots() ax.plot(range(1,6), range(5)) plt.xticks(range(1,6), ['a','b','c','d','e'])  labels = ['(%s)' % l.get_text() l in ax.xaxis.get_ticklabels()] ax.xaxis.set_ticklabels(labels) 

your code l.get_text() in list comp there l.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -