python坐标轴刻度设置对数_用对数刻度设置刻度
我將添加一些圖并顯示如何刪除較小的刻度線:
OP:
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()
如tcaswell所指出的,要添加一些特定的刻度,可以使用? matplotlib.ticker.ScalarFormatter:
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()
要刪除較小的滴答聲,可以使用matplotlib.rcParams['xtick.minor.size']:
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()
您可以改用? ax1.get_xaxis().set_tick_params,它具有相同的效果(但僅修改當前軸,并非所有以后的圖形都與不同matplotlib.rcParams):
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()
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的python坐标轴刻度设置对数_用对数刻度设置刻度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++ 线性回归_模型之母:简单线性回归
- 下一篇: Requirements of pair