Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot multiple boxplot in one graph in pandas or matplotlib?

I have a two boxplotes

a1=a[['kCH4_sync','week_days']]
a1.boxplot(by = 'week_days', meanline=True, showmeans=True, showcaps=True, showbox=True,            
                 showfliers=False)
a2=a[['CH4_sync','week_days']]
a2.boxplot(by = 'week_days', meanline=True, showmeans=True, showcaps=True, showbox=True,     
                 showfliers=False)

But I want to place them in one graph to compare them. Have you any advice to solve this problem? Thanks!

like image 777
Shin Avatar asked Nov 21 '14 12:11

Shin


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.

How do I plot a boxplot in Matplotlib?

Creating Box PlotThe matplotlib. pyplot module of matplotlib library provides boxplot() function with the help of which we can create box plots. The data values given to the ax. boxplot() method can be a Numpy array or Python list or Tuple of arrays.


1 Answers

To plot multiple boxplots on one matplotlib graph you can pass a list of data arrays to boxplot, as in:

import numpy as np
import matplotlib.pyplot as plt

x1 = 10*np.random.random(100)
x2 = 10*np.random.exponential(0.5, 100)
x3 = 10*np.random.normal(0, 0.4, 100)
plt.boxplot ([x1, x2, x3])

The only thing I am not sure of is if you want each boxplot to have a different color etc. Generally it won't plot in different colour

like image 111
rhody Avatar answered Sep 28 '22 15:09

rhody