Skip to content Skip to sidebar Skip to footer

How To Unseparate Plots In Boxplot

I have plotted a box plot through a directory that has 6 subfolders within. When I write plt.boxplot(my_list) with writing plt.show() it plots 6 different graphs and without writin

Solution 1:

The trick is passing a list to positions. Also, plt.show() must be called outside the loop.

Here is a quick example:

import matplotlib.pyplot as plt

a = [1,2,3,4,5,6]
b = [5,6,7,8,9]

data = [a,b]

for i, x in enumerate(data):
    plt.boxplot(x, positions=[i])
plt.show()

enter image description here

You can always change the ticks labels with anything you want.

In this case, you I change [0,1] to ['dir_A','dir_B']:

plt.xticks([0,1], ['dir_A','dir_B'])
plot.show()

enter image description here

Post a Comment for "How To Unseparate Plots In Boxplot"