设置对数刻度的刻度
看来, set_xticks不是在日志范围内工作: 
 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, 200, 500]) plt.show() 
可能吗?
 import matplotlib 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, 200, 500]) ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter()) 
要么
 ax1.get_xaxis().get_major_formatter().labelOnlyBase = False plt.show() 
  
 
我将添加一些情节,并展示如何删除小勾号:
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'] ,可以使用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不是所有未来的graphics): 
 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() 
  
 
  set_xticks作品,如果你仔细观察,它会把主要的set_xticks (蜱比其他的要长)。 与没有调用set_xticks的同一个plot进行set_xticks 。 
 重点是set_xticks设置蜱,而不是ticklabels。 如果你想标签添加 
 ax1.set_xticklabels(["20", "200", "500"]) 
之前plt.show()