Split multi-line block on one chart in pandas or matplotlib?

I have two drawers

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 on one chart to compare them. Do you have any tips to solve this problem? Thanks!

+5
source share
2 answers

Use return_type='axes' to get a1.boxplot to return the matplotlib Axes object. Then pass these axes to the second boxplot call using ax=ax . This will cause both drawers to be drawn on the same axes.

 a1=a[['kCH4_sync','week_days']] ax = a1.boxplot(by='week_days', meanline=True, showmeans=True, showcaps=True, showbox=True, showfliers=False, return_type='axes') a2 = a[['CH4_sync','week_days']] a2.boxplot(by='week_days', meanline=True, showmeans=True, showcaps=True, showbox=True, showfliers=False, ax=ax) 
+5
source

To build multiple boxes on the same matplotlib graph, you can transfer the list of data arrays to boxplot, as in:

 import nump as np import matplotlib.pyplot as plt x1 = 10*np.random.random(100) x = 10*np.random.exponential(0.5, 100) x = 10*np.random.normal(0, 0.4, 100) plt.boxplot ([x1, x2, x3]) 

The only thing I'm not sure about is that you want each boxplot to have a different color, etc.

0
source

Source: https://habr.com/ru/post/1207401/


All Articles