python - 如何用Python编程绘制wifi信道图
问题描述
嗨,我是 python 图的初学者
我有一些像这样的wifi数据(Dataframe)
SSID | 接收信号强度指数 | 渠道 | r_range | l_range | 带宽 |
---|---|---|---|---|---|
ASUS_Kurt | -76 | 2 | 0.0 | 4.0 | 20MHz |
Javen-2.4G | -91 | 3 | 1.0 | 9.0 | 40MHz |
林 | -62 | 6 | 4.0 | 8.0 | 20MHz |
wcs2.4G | -64 | 11 | 9.0 | 13.0 | 20MHz |
LIN-EXT | -74 | 11 | 5.0 | 13.0 | 40MHz |
如何使用 matplotlib 或 seaborn 绘制这样的 Wifi-Channel 图
我尝试这样的代码:
plt.cla()
a = [['test', -87, 6, 4, 8]]
df = pd.DataFrame(a, columns=['ssid', 'rssi', 'channel', 'r', 'l'])
x = np.linspace(df['r'], df['l'], 50)
y = int(df['rssi']) * np.sin((x - int(df['channel']) + 2) / 4 * np.pi)
plt.fill(x, y, color='r', alpha=0.3)
plt.show()
像这样打印图表
不是我想要的。
y.value
应该是-99
和0
应该frequency height
是一样-99
,-87
只有13
通道中的高度6
解决方案
如果我使用-99
(或-100
)
y = (-99 - row['rssi']) * ...
和
y = -99 - y
然后我翻转值并得到预期的情节
最小的工作代码。
顺便说一句:对于某些范围(l - r > 4
),它需要不同的计算。
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
data = [
('ASUS_Kurt', -76, 2, 0.0, 4.0),
# ('Javen-2.4G', -91, 3, 1.0, 9.0), # need different calculations
('LIN', -62, 6, 4.0, 8.0),
('wcs2.4G', -64, 11, 9.0, 13.0),
# ('LIN-EXT', -74, 11, 5.0, 13.0), # need different calculations
('test1', -87, 6, 4.0, 8.0),
('test2', -80, 11, 9.0, 13.0),
]
df = pd.DataFrame(data, columns=['ssid', 'rssi', 'channel', 'r', 'l'])
plt.cla()
all_colors = ['r', 'g', 'b', 'y']
for index, row in df.iterrows():
x = np.linspace(row['r'], row['l'], 50)
y = (-99-row['rssi']) * np.sin((x - row['channel'] + 2) / 4 * np.pi)
y = -99-y
color = all_colors[ index % len(all_colors) ]
plt.fill(x, y, color=color, alpha=0.3)
plt.show()
编辑:
Javen-2.4G
并且LIN-EXT
可能需要不同的计算,因为channel
它不在r
和之间l
。
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
data = [
('ASUS_Kurt', -76, 2, 0.0, 4.0),
('Javen-2.4G', -91, 3, 1.0, 9.0), # need different calculations
('LIN', -62, 6, 4.0, 8.0),
('wcs2.4G', -64, 11, 9.0, 13.0),
('LIN-EXT', -74, 11, 5.0, 13.0), # need different calculations
('test1', -87, 6, 4.0, 8.0),
('test2', -80, 11, 9.0, 13.0),
]
df = pd.DataFrame(data, columns=['ssid', 'rssi', 'channel', 'r', 'l'])
all_colors = ['r', 'g', 'b', 'y']
plt.cla()
plt.xlabel('Wifi Channel')
plt.ylabel('Signal Strength [dBm]')
plt.grid(axis='y', linestyle='--')
plt.grid(axis='x', linestyle=':', color='r', alpha=0.3)
y_major_ticks = np.arange(0, -100, -10)
plt.gca().set_yticks(y_major_ticks)
x_major_ticks = np.arange(0, 15, 1)
plt.gca().set_xticks(x_major_ticks)
plt.ylim(-100, 0)
plt.xlim(-2, 16)
for index, row in df.iterrows():
diff = (row['l'] - row['r'])
x = np.linspace(row['r'], row['l'], 50)
y = (-99-row['rssi']) * np.sin((x - row['r']) / diff * np.pi)
y = -99-y
color = all_colors[ index % len(all_colors) ]
plt.fill(x, y, color=color, alpha=0.3)
plt.plot(x, y, color=color)
plt.text(row['channel'], row['rssi']+1, row['ssid'], horizontalalignment='center')
plt.show()
推荐阅读
- android - Android 版 Chrome 上的深层链接无法正常工作
- html - HTML 表单似乎正确但未提交
- flutter - 有没有办法在 vscode/visual studio 代码颤动中自动填充所需的类/小部件属性?
- batch-file - 打开带有/不带参数的批处理文件
- python - 递归计算具有最大位移的排列数
- ruby-on-rails - 后台控制器的未定义方法
- css - CSS 特殊性 - 内部样式、内联样式和外部样式
- python - 连续整数排序列表的最小交换
- r - 在您的条形图中制作具有多个堆叠部分的黑白 ggplot 条形图的最佳方法?
- r - R如何从Excel范围创建图像文件