Skip to content
Advertisement

Changing axis ticks in Matplotlib with multiple connected Boxplots

I am plotting a convergence graph and to show deviations from the mean I am using connected boxplots:Connected boxplots

For some reason Matplotlib forces ticks for each boxplot and I cannot seem to get them removed. My code for the current plot looks something like this:

JavaScript

I have tried multiple ways of manipulating axis ticks which are available in MPL.

1) Trying to let MPL do the work: ax.xaxis.set_major_locator(MultipleLocator(20))

2) Trying to set ticks manually: ax.set_xticks([list_of_ticks])

3) Tried a workaround

JavaScript

None of these seemed to work and I am unsure why. I think it may have something to do with my label variable but if I don’t include it in this way MPL with include an axis lable for every entry which is a mess.

How can I set axis ticks once every 1000 entries in a connected boxplots figure?`

Edit: The input data is a numpy array of shape (15, 160) s.t. there are 160 boxplots plotted of 15 samples each. Example data for 5 boxplots of 3 samples each would look like:

JavaScript

Advertisement

Answer

The main issue seems to be that the ticks need to be updated after drawing the main plot, never before.

(Having ax = fig.add_axes([0, 0, 1, 1]) is also quite unusual to work with. The standard way is fig, ax = plt.subplots(figsize=(10, 5)) which lets matplotlib a bit of flexibility for the whitespace around the plot.)

The code of the question has some missing variables and data, but the following toy example should create something similar:

JavaScript

example plot

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement