我正在尝试使用matplotlib.pyplot.semilogy在半对数刻度上显示数据,但出于某种原因某些特定数据不会以对数刻度显示。
这是最小的例子:
import numpy as np
import matplotlib.pyplot as plt
x1 = np.linspace(0, 1, 50)
y1 = np.linspace(0.1, 10, 50)
x2 = [ 0.5, 0.69230769, 0.88461538, 1.07692308, 1.26923077, 1.46153846,
1.65384615, 1.84615385, 2.03846154, 2.23076923, 2.42307692, 2.61538462,
2.80769231, 3., 3.19230769, 3.38461538, 3.57692308, 3.76923077,
3.96153846, 4.15384615, 4.34615385, 4.53846154, 4.73076923, 4.92307692,
5.11538462, 5.30769231, 5.5, 5.69230769, 5.88461538, 6.07692308,
6.26923077, 6.46153846, 6.65384615, 6.84615385, 7.03846154, 7.23076923,
7.42307692, 7.61538462, 7.80769231, 8. ]
y2 = [14.575361987617431, 13.085951334251263, 11.624204239934841, 11.042131295677322, 10.644970825480804,
9.9236653345614503, 9.5062099711101915, 9.3283627736535824, 9.0534046482183932, 8.8134672834907359,
8.4231263934928542, 8.42795792391086, 8.4456426949395116, 8.0627962362862267, 8.164485063139546,
7.9551127994296023, 7.8244362249461439, 7.9030927230355665, 7.7181207757466472, 7.5995483354781648,
7.5188031175401084, 7.5583740928502579, 7.5662853869793665, 7.437330171526578, 7.3623785273467872,
7.3503413700294535, 7.375341864137301, 7.300590983871917, 7.2357339123237017, 7.1353470647499266,
7.1784115809287599, 7.1576686293908374, 7.097654663701598, 6.9911420242692399, 7.0015210243972046,
6.9017431583355604,6.9352210046151539, 6.8707305411431996, 6.7925239329688045, 6.7930737708109978]
plt.figure(1)
plt.subplot(2,1,1)
# plt.plot(x1, y1, 'o-')
plt.plot(x2, y2, 'o-')
plt.title('Linear Scale')
plt.subplot(2,1,2)
# plt.semilogy(x1, y1, 'o-')
plt.semilogy(x2, y2, 'o-')
plt.title('Semi-Log Scale')
plt.subplots_adjust(top=0.95, bottom=0.05, hspace = 0.25)
plt.show()
但如果我绘制x1和y1而不是它似乎正常工作:
我不确定为什么会这样,也许半导体中有一个错误?有没有人知道解决方法?
我在python版本3.6.3上使用matplotlib版本2.1.0