如何更改PSD图中的yticks?

时间:2019-10-14 08:57:27

标签: python matplotlib

Download Zip with signal.csv

我可以这样创建psd plot

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.read_csv('signal.csv')/1000
dt = df.iloc[1,0] - df.iloc[0,0]
data=df['1']
print(f'time delta: {dt*1e12:.0f} ps')
print(f'time: {(len(data)*dt*1e6):.3f} \u03BCs')


resolution = 2000
plt.psd(data,
        resolution,
        1/0.1,
        lw=1,
        color='red');
plt.xlim(0,5)
plt.xlabel('Frequency / GHz')
plt.ylabel('Power Spectral Density / dB/Hz')
plt.show()

enter image description here

我该如何改变其钇ick率?当我尝试添加时:

plt.yticks(np.arange(-100,0,10))

整个图形变形:

enter image description here

如何更改psd plot,以使y轴以10表示,而不更改绘图?

1 个答案:

答案 0 :(得分:1)

您只需要再次设置y-lim:

plt.ylim((-72,-25))

,您可以调整限制以匹配所需的输出。

修改 如果要使其自动运行,可以使用axs.get_ylim()

fig, axs = plt.subplots(figsize=(10, 10),constrained_layout=True)
axs.psd(data,resolution,1/0.1,lw=1,color='red')

axs.set_xlim(0,5)
axs.set_xlabel('Frequency / GHz')
axs.set_ylabel('Power Spectral Density / dB/Hz')

ylim=axs.get_ylim()
axs.set_yticks(np.arange(-100,0,10))
axs.set_ylim(ylim)

enter image description here