Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating multiple boxplots on the same graph from a dictionary

I am trying to create a graph whereby the x axis is the key of the dictionary and the boxplot is from the information inside the dictionary. My dictionary can have many keys.

Data = {'ABC': [34.54, 34.345, 34.761], 'DEF': [34.541, 34.748, 34.482]}

for ID in Data:      
        plt.boxplot(Data[ID])
        plt.xlabel(ID)
plt.savefig('BoxPlot.png')
plt.clf()

It however seems to put the box plots on top of each other. I tried iterating the positions value within boxplot with no luck. I would also like to use the key as the xaxis value for each boxplot if possible.

like image 417
Tom Pitts Avatar asked Sep 11 '18 10:09

Tom Pitts


People also ask

How do you plot multiple box plots?

In this article, we will learn how to plot multiple boxplot in one graph in R Programming Language. This can be accomplished by using boxplot() function, and we can also pass in a list, data frame or multiple vectors to it. For this purpose, we need to put name of data into boxplot() function as input.

Can boxplots plot several data sets side-by-side?

Side-By-Side boxplots are used to display the distribution of several quantitative variables or a single quantitative variable along with a categorical variable.


1 Answers

my_dict = {'ABC': [34.54, 34.345, 34.761], 'DEF': [34.541, 34.748, 34.482]}

fig, ax = plt.subplots()
ax.boxplot(my_dict.values())
ax.set_xticklabels(my_dict.keys())

enter image description here

like image 83
Diziet Asahi Avatar answered Sep 26 '22 08:09

Diziet Asahi