对数刻度轴刻度&设置自定义线性刻度后未删除标签

时间:2017-10-26 20:14:39

标签: python python-3.x matplotlib

我正在使用matplotlib进行策划。当我将x刻度设置为'log'并更改刻度标签和格式以线性显示时,日志空间刻度标签不会消失,我最终得到两组xticklabels(一个线性和一个日志空间)

这在其他机器上没有发生,所以我认为它是特定于版本的?现在我正在使用matplotlib 2.0.2和python 3.6.1在Jupyter Notebook中工作。

MWE:

import numpy as np
import matplotlib.pyplot as plt    
from matplotlib.ticker import FormatStrFormatter
%matplotlib inline
fig, ax = plt.subplots(1, 1)
xmin = 5
xmax = 50
ax.set_xscale('log')
ax.set_xticklabels(np.logspace(np.log10(xmin), np.log10(xmax), num=6))
ax.set_xticks(np.logspace(np.log10(xmin), np.log10(xmax), num=6))
ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))
ax.set_xlim([xmin, xmax])

enter image description here

0 个答案:

没有答案
相关问题