irene
irene

Reputation: 2243

Custom spacing between groups in boxplots

There's a thread on stackoverflow with exactly the same question, but it is for Matlab. However, I'm using matplotlib and I don't know how to proceed. Basically, I have a number of boxplots, but I want to separate them like this (copied shamelessly from the thread above):

enter image description here

How can I go about this? There's a suggestion to put an invisible boxplot in between the two groups, but I don't know how to make the tick (not just the label) vanish only for that value.

Upvotes: 2

Views: 1885

Answers (1)

SpghttCd
SpghttCd

Reputation: 10860

There's a keyword positions in matplotlib's boxplot (here put as first parameter for focusing reason):

import matplotlib.pyplot as plt
plt.boxplot(positions=[0, 1, 2, 5, 6], labels=['1\na', '1\nb', '1\nc', '2\na', '2\nb'],
    x=[np.random.random_sample(100)-.05, np.random.random_sample(100), np.random.random_sample(100)+.1, np.random.random_sample(100)+.2, np.random.random_sample(100)+.3])

enter image description here

Upvotes: 5

Related Questions