擅长:python、mysql、java
<p>熊猫<code>subplots=True</code>将在一列中排列轴。</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame(np.random.rand(7,20))
df.plot(subplots=True)
plt.tight_layout()
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/KniKs.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KniKs.png" alt="enter image description here"/></a></p>
<p>这里,<code>tight_layout</code>不应用,因为图形太小,无法很好地排列轴。不过,人们可以使用更大的数字(<code>figsize=(...)</code>)。</p>
<p>为了使轴在网格上,可以使用<code>layout</code>参数,例如</p>
<pre><code>df.plot(subplots=True, layout=(4,5))
</code></pre>
<p><a href="https://i.stack.imgur.com/6At26.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6At26.png" alt="enter image description here"/></a></p>
<p>如果通过<code>plt.subplots()</code>创建轴,也可以实现相同的效果</p>
<pre><code>fig, axes = plt.subplots(nrows=4, ncols=5)
df.plot(subplots=True, ax=axes)
</code></pre>