Changing tick marks of the x axis when working with subheadings

I draw several boxes on the same shape using matplotlib, following the example here:
http://matplotlib.org/examples/pylab_examples/subplots_demo.html

Everything works as expected, but I can't figure out how to change the label labels on the x axis. I have four rows of data that are being built, but the x-axis ticks are labeled “1, 2, 3, 4,” where I would like to assign text to these values.

My build code is as follows:

f, axarr = plt.subplots(2, sharex=True) axarr[0].boxplot(WS_Bias, whis = 100) #axarr[0].xticks(range(1, len(Labels)+1),Labels) axarr[0].axhspan(-0.5, 0.5, facecolor='c', alpha = 0.2) axarr[1].boxplot(WS_RMS, whis = 100) #axarr[1].xticks(range(1, len(Labels)+1),Labels) axarr[1].axhspan(0, 2, facecolor='c', alpha = 0.2) pl.show() 

The recorded lines worked on changing labels when I was dealing with only one data set, but this command is not recognized by the methods that I use. Pyplot is imported as plt.

+6
source share
1 answer

Suppose axarr[0] has 4 visible x tick labels ( [1,2,3,4] ) and what you want instead is ['a', 'b', 'c', 'd']

You can set the x tick marks with the Axes set_xticklabels method, just by doing this:

 axarr[0].set_xticklabels(['a', 'b', 'c', 'd']) 

Relatively

The recorded lines worked on changing labels when I was dealing with only one data set, but this command is not recognized by the methods that I use

xticks is not an Axes method, but a function from matplotlib.pyplot , which (I think) wraps set/get_xticks and set/get_xtickslabels . Therefore, if you try to use it, as in your code, you should receive an error message.

+13
source

Source: https://habr.com/ru/post/957429/


All Articles