(已解决)尝试创建Y轴为对数刻度但不使用科学计数法显示值的图。 [重复]已解决问题的问题和解决方案代码如下所示。
问题:
import matplotlib.pyplot as plt
import numpy as np
#Input data:
time = [0, 5, 10, 15]
data = [100, 47, 4, 1]
#Make plot:
plt.plot(time, data, color='blue')
plt.xticks(np.arange(min(time), max(time) + 1, 5))
plt.gca().spines['right'].set_color('none')
plt.gca().spines['top'].set_color('none')
plt.yscale('log')
plt.show()
解决方案:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mticker
#Input data:
time = [0, 5, 10, 15]
data = [100, 47, 4, 1]
#Make plot:
plt.plot(time, data, color='blue')
plt.xticks(np.arange(min(time), max(time) + 1, 5))
plt.gca().spines['right'].set_color('none')
plt.gca().spines['top'].set_color('none')
plt.yscale('log')
ax = plt.gca()
ax.yaxis.set_major_formatter(mticker.ScalarFormatter())
plt.show()