我希望能够绘制一些关于频率的图表。我想要一个带有上标符号的x轴,就像这里所示。
此外,我需要在千赫和兆赫之间使用垂直线和垂直注释进行分隔。
我尝试使用 ticker,但不知道如何设置。我尝试按照一些示例操作,但出现错误,例如
import numpy as np
import matplotlib.pyplot as plt
band = np.linspace(0,10**12,100)
y = band
plt.plot(band,y)
plt.xlabel('Frequencies')
plt.vlines(10**3, min(y), max(y),colors = 'black', label = 'kilo Hz')
plt.vlines(10**6, min(y), max(y),colors = 'black', label = 'mega Hz')
plt.legend()
plt.show()
我尝试使用 ticker,但不知道如何设置。我尝试按照一些示例操作,但出现错误,例如
AttributeError:'Figure'对象没有'ticklabel_format'属性
。我已经花了很多时间在这上面,不知道该怎么继续。
总的来说,我需要x轴以类似于plt.xscale('log')
的方式格式化,但我想保持线性刻度。
axvline
替代vlines
来绘制您的垂直线。 - tacaswellmatplotlib.ticker.Formatter
,并且我尝试了很多已经不存在的行。对于set_major_formatter
,我会收到类似object has no attribute
的错误。 - tomasz74set_major_formatter
?这是axis
对象的方法(而不是axes
)。例如:yaxis = ax.get_yaxis()
。 - tacaswell