擅长:python、mysql、java
<p><a href="https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.grid.html#matplotlib.axes.Axes.grid" rel="noreferrer">According to matplotlib documentation</a>,<code>Axes</code>类<code>grid()</code>方法的签名如下:</p>
<blockquote>
<p>Axes.grid(b=None, which='major', axis='both', **kwargs)<br/>
Turn the axes grids on or off. </p>
<p><code>which</code> can be ‘major’ (default), ‘minor’, or ‘both’ to control whether
major tick grids, minor tick grids, or both are affected.</p>
<p><code>axis</code> can be ‘both’ (default), ‘x’, or ‘y’ to control which set of
gridlines are drawn.</p>
</blockquote>
<p>因此,为了显示x轴和y轴的网格线,我们可以使用以下代码:</p>
<pre><code>ax = plt.gca()
ax.grid(which='major', axis='both', linestyle='--')
</code></pre>
<p>此方法使我们能够更好地控制网格线的显示内容。</p>