For a given dataset I am plotting a box plot of size of object at 10 different points as below:
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib as mpl
font_prop = font_manager.FontProperties( size=18)
def plot (path, name=""):
df = pd.read_csv(path, index_col=0)
df = df.dropna()
Position = [1 + i // df.shape[0] for i in range(df.size)]
df_n = [df[col] for col in df.columns]
df_t = pd.concat(df_n).tolist()
groups = [[] for i in range(max(Position))]
[groups[Position[i] - 1].append(df_t[i]) for i in range(len(df_t))]
plt.figure(figsize=(12, 5))
plt.scatter(Position, df_t, color='g')
b = plt.boxplot(groups, patch_artist=False)
for median in b['medians']:
median.set(color='r', linewidth=2)
A typical graph would be like this:
I have 4 different datasets and I would like to present a graph where on the position axis (x axis) there will be 4 bar plots above each position. How would I modify my code to do that?
Here is the sample dataset: https://github.com/aebk2015/multipleboxplot.git
,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,Class
1,7.6,1.0,1.0,1.0,1.0,6.0,49.0,1.0,1.0,40.0,L
2,9.7,2.7,5.6,1.0,1.0,1.0,34.0,1.0,1.0,1.0,L
3,1.0,6.0,1.0,1.0,1.0,3.0,39.0,1.0,28.0,1.0,L
4,8.0,25.5,1.0,1.0,1.0,1.0,24.0,1.0,1.0,1.0,L
5,1.0,29.0,1.0,1.0,1.0,1.0,38.0,29.0,20.0,1.0,L
6,4.0,34.0,1.0,1.0,1.0,39.0,14.0,1.0,12.0,1.0,L
7,1.0,17.0,1.0,1.0,1.0,1.0,20.8,1.0,14.6,1.0,L
8,1.0,1.0,1.0,1.0,1.0,1.0,19.0,17.5,1.0,1.0,L
9,1.0,30.0,1.0,1.0,1.0,3.0,23.0,1.0,1.0,1.0,L
10,1.0,5.0,25.0,1.0,1.0,17.0,6.3,1.0,17.0,1.0,L
1,11.8,19.0,1.0,1.0,1.0,11.3,2.0,4.0,5.0,1.0,C
2,12.0,17.0,20.0,9.0,1.0,23.0,4.0,7.0,1.0,1.0,C
3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