简体   繁体   English

Plot 幅度 [dB] 与频率 [deg] 与 matplotlib.pyplot python 其中 Mag 和 Freq 是两个列表

[英]Plot Magnitude[dB] vs. Frequency[deg] with matplotlib.pyplot python where Mag and Freq are two lists

# plotting Magnitud vs. Freq
figure1 = plt.Figure(figsize=(5,4), dpi=100)
ax1 = figure1.add_subplot(111)
ax1.plot(freq, mag_S11, color = 'r')
# ax1.set_ylim([-75, 50])
# ax1.set_xlim([0.0, 30.0])
scatter = FigureCanvasTkAgg(figure1, root) 
scatter.get_tk_widget().pack(side=tk.RIGHT, fill=tk.BOTH)
ax1.legend(['S11']) 
ax1.set_xlabel('Frequency [GHz]')
ax1.set_title('Magnitude[dB] Vs. Frequency')

My freq and mag_S11 are 2 lists of more than 200 elements, the problem is I'm not getting the graph behavior I want.我的freqmag_S11是 2 个超过 200 个元素的列表,问题是我没有得到我想要的图形行为。 Am I plotting it correctly or the values are wrong?我是正确地绘制它还是值是错误的?

This is what I'm getting:这就是我得到的:

在此处输入图像描述

This is what I want:这就是我要的:

在此处输入图像描述

Any help would be really appreciated.任何帮助将非常感激。

That is because plot connects the dots.那是因为plot连接了这些点。 You want to either use ax1.scatter(...) with the current data or ax1.plot(...) with the data sorted so that x increases.您想将ax1.scatter(...)与当前数据一起使用,或者将ax1.plot(...)与排序的数据一起使用,以便 x 增加。 Using使用

 freq, mag_S11 = sorted([freq, mag_S11], key=lambda x: x[0])

should sort both datasets by increasing frequency and let the plot work nicely.应该通过增加频率对两个数据集进行排序,并让 plot 正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM