modify pandas boxplot output
<p>I made this plot in pandas, according to the documentation:</p>

<pre><code>import pandas as pd
import numpy as np
import pyplot as plt

df = pd.DataFrame(np.random.rand(140, 4), columns=['A', 'B', 'C', 'D'])
df['models'] = pd.Series(np.repeat(['model1','model2', 'model3', 'model4', 'model5', 'model6', 'model7'], 20))
plt.figure()
bp = df.boxplot(by="models")
</code></pre>

<p><a href="https://i.stack.imgur.com/2So7W.png" rel="nofollow"><img src="https://i.stack.imgur.com/2So7W.png" alt="enter image description here"></a></p>

<p>How can I modify this plot?</p>

<p>I want:</p>

<ul>
<li>modify arrangement from (2,2) to (1,4)</li>
<li>change the labels and titles, text and font size</li>
<li>remove the '[models]' text</li>
</ul>

<p>and how do I save this plot as pdf ?</p>

<ul>
<li>For the arrangement use <code>layout</code></li>
<li>For setting x label use <code>set_xlabel('')</code></li>
<li>For figure title use <code>figure.subtitle()</code></li>
<li>For changing the figure size use <code>figsize=(w,h)</code> (inches)</li>
</ul>

<p>note: the line <code>np.asarray(bp).reshape(-1)</code> is converting the layout of the subplots (2x2 for instance) to an array. </p>

<p>code : </p>

<pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.DataFrame(np.random.rand(140, 4), columns=['A', 'B', 'C', 'D'])
df['models'] = pd.Series(np.repeat(['model1','model2', 'model3', 'model4', 'model5', 'model6', 'model7'], 20))
bp = df.boxplot(by="models",layout=(4,1),figsize=(6,8))
[ax_tmp.set_xlabel('') for ax_tmp in np.asarray(bp).reshape(-1)]
fig = np.asarray(bp).reshape(-1)[0].get_figure()
fig.suptitle('New title here')
plt.show()
</code></pre>

<p>result: </p>

<p><a href="https://i.stack.imgur.com/jRV5z.png" rel="nofollow"><img src="https://i.stack.imgur.com/jRV5z.png" alt="enter image description here"></a></p>

python pandas matplotlib