python - 如何解释这个等高线图?
问题描述
我正在使用传感器进行室内定位项目,并准备了一个如下所示的数据集:
1 0 0 30.263302
2 0 1 30.154142
3 0 2 30.159311
4 1 0 29.978758
5 1 1 29.802172
6 1 2 29.716825
7 2 0 29.671733
8 2 1 29.642293
9 2 2 29.573582
以上数据是我从应用程序收集的传感器读数的平均值。后两列只是坐标(例如 0,0 0,1 0,2....2,2),最后一列是传感器数据的平均值。
我已经创建了一个情节,但我无法理解如何理解它。那么任何人都可以帮助我理解下图中发生了什么吗?
解决方案
这是一种根据您的数据创建类似图的方法。请注意,您的值约为 30,而您的示例图的值在 0.1 - 2.1 范围内。
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
M, N = 24, 15
df = pd.DataFrame({'X': np.repeat(np.arange(M), N),
'Y': np.tile(np.arange(N), M),
'Val': 30 + np.random.normal(size=(M, N)).cumsum(axis=0).cumsum(axis=1).ravel() / 2})
fig, (ax1, ax2) = plt.subplots(ncols=2)
scat = ax1.scatter(df['X'], df['Y'], c=df['Val'], cmap='Spectral')
plt.colorbar(scat, ax=ax1)
ax1.set_title('just the values')
xs = df['X'].to_numpy().reshape(M, N)
ys = df['Y'].to_numpy().reshape(M, N)
vals = df['Val'].to_numpy().reshape(M, N)
contours = ax2.contour(xs, ys, vals, cmap='Spectral')
ax2.clabel(contours, inline=1, fmt='%.1f', fontsize=10)
plt.colorbar(contours, ax=ax2)
ax2.set_title('isolines')
plt.show()
演示数据如下:
X Y Val
0 0 0 30.505696
1 0 1 30.617889
2 0 2 30.585834
3 0 3 31.455314
4 0 4 30.897253
因此,对于每个 xy 网格点,都有一个测量值。散点图为每个测量显示一个点,其颜色表示其值。
ax.contour()
创建连接估计测量值具有相同值的所有点的等高线(或等值线)。ax.clabel()
添加文本标签以显示值。在这种情况下,等值线和文本与散点图具有相同的颜色,以便更好地查看对应关系。相反,选择固定颜色会生成与示例类似的图。
除了ax.contour()
需要 x 和 y 位于网格上之外,还有ax.tricontour()
x 和 y 可以更自由地定位的地方。
推荐阅读
- entity-framework - 将 c++/cli 实体映射到表(实体框架)
- php - 我的 API 请求无缘无故地使用了 25 个请求
- java - getAllEntriesByKey 导致错误:Vector 中的对象类型未知或不受支持
- javascript - ES6 合并两个 FileList,更新一个 input.files 元素
- .htaccess - URL 路由/重写
- ios - 使用新属性扩展 UIView
- swift - 在 Swift 中将 BOM 写入流式传输
- php - 检查谁在服务器中进行了更改
- ios - 在 Xcode 10 升级后运行 createIPA 任务
- javascript - 每次我包含一个 scss 文件时,使用 Typescript、Webpack 4 和 React,样式名称在 className 中未定义