<p>我将添加一些绘图并演示如何删除次要刻度:</p>
<p>手术室:</p>
<pre><code>from matplotlib import pyplot as plt
fig1, ax1 = plt.subplots()
ax1.plot([10, 100, 1000], [1,2,3])
ax1.set_xscale('log')
ax1.set_xticks([20, 300, 500])
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/wwlsr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wwlsr.png" alt="enter image description here"/></a></p>
<p>要添加一些特定的记号,如<a href="https://stackoverflow.com/users/380231/tcaswell">tcaswell</a>所指出的,可以使用<a href="http://matplotlib.org/api/ticker_api.html#matplotlib.ticker.ScalarFormatter" rel="noreferrer">^{<cd1>}</a>:</p>
<pre><code>from matplotlib import pyplot as plt
import matplotlib.ticker
fig1, ax1 = plt.subplots()
ax1.plot([10, 100, 1000], [1,2,3])
ax1.set_xscale('log')
ax1.set_xticks([20, 300, 500])
ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/AIDlR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AIDlR.png" alt="enter image description here"/></a></p>
<p>要删除次要记号,可以使用<a href="http://matplotlib.org/users/customizing.html" rel="noreferrer">^{<cd2>}</a>:</p>
<pre><code>from matplotlib import pyplot as plt
import matplotlib.ticker
matplotlib.rcParams['xtick.minor.size'] = 0
matplotlib.rcParams['xtick.minor.width'] = 0
fig1, ax1 = plt.subplots()
ax1.plot([10, 100, 1000], [1,2,3])
ax1.set_xscale('log')
ax1.set_xticks([20, 300, 500])
ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/pyzs5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pyzs5.png" alt="enter image description here"/></a></p>
<p>您可以使用<a href="http://matplotlib.org/api/axis_api.html" rel="noreferrer">^{<cd3>}</a>,它有相同的效果(但只修改当前轴,而不是所有未来的图形不同于<code>matplotlib.rcParams</code>):</p>
<pre><code>from matplotlib import pyplot as plt
import matplotlib.ticker
fig1, ax1 = plt.subplots()
ax1.plot([10, 100, 1000], [1,2,3])
ax1.set_xscale('log')
ax1.set_xticks([20, 300, 500])
ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
ax1.get_xaxis().set_tick_params(which='minor', size=0)
ax1.get_xaxis().set_tick_params(which='minor', width=0)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/pyzs5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pyzs5.png" alt="enter image description here"/></a></p>