Skip to content
Advertisement

Plotting multiple boxplots in seaborn

I want to plot boxplots using seaborn in pandas because it is a nicer way to visualize data, but I am not too familiar with it. I have three dataframes that are different metrics, and I want to compare the different metrics. I will loop through the file paths to access them.

JavaScript

The dfs for each of the metrics are separate and look something like this (where the …. indicates filled in data values). 1, 2, 3, 4, 5 are the column names and indicate different trials :

JavaScript

I want to have all the plots for trials 1, 2, 3, 4, 5 and each of the 3 metrics side by side, where all the first trial plots for the three metrics would be on the left, then all the second trial plots would be to the right of that, and so on.

How could I go about doing this in seaborn? I know I can do a plot individually for each metric by looping through the path and using the boxplot function like this:

JavaScript

However, how would I be able to fit the other metrics’ plots side-by-side on the same plot?

Advertisement

Answer

Consider first assigning a grouping column like Trial for each corresponding dataframe, then pd.concat your dataframes, and finally pd.melt the data for a indicator/value long-wise dataframe before plotting with seaborn. Below demonstrates with random data:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement