【发布时间】:2022-06-14 20:21:04
【问题描述】:
我正在查看一些磁盘厚度的数据,并尝试使用 matplotlib 轮廓绘制它。
我所拥有的让我能够制作出这样的东西:
我想要的更像是:
我所能找到的与轮廓相关的只是 Z 是一个方程,而不是散点。
也许我需要一个补全/插值函数来补全缺失的部分。
以下是一些用于测试的数据,我无法从 plt.contourf 的正确设置中得出一些结果
把它放在一个圈子里很好,但不是强制性的。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
a = pd.DataFrame({'X': [-9, -5, -5, -5, -3, -3, -3, 0, 0, 0, 3, 3, 3, 5, 5, 5, 9],
'Y':[0, -5, 0, 5, -3, 0, 3, -9, 0, 9, -3, 0, 3, -5, 0, 5, 0],
'Z':[5, 5.1, 5, 5, 5.4, 5.1, 5.3, 5.9, 5, 5, 5.3, 5.1, 5, 5.2, 5.3, 5.4, 5.]})
##%
a_pivoted = a.pivot_table(index='Y', columns='X', values='Z')
ax = sns.heatmap(a_pivoted, annot=True)
##%
X, Y = np.meshgrid(np.unique(a['X']), np.unique(a['Y']))
Z = a.pivot_table(index='Y', columns='X', values='Z').values
fig,ax=plt.subplots(1,1)
cp = ax.contourf(X, Y, Z)
ax.set_title('Filled Contours Plot')
ax.set_xlabel('x (cm)')
ax.set_ylabel('y (cm)')
plt.show()
【问题讨论】:
标签: python matplotlib surface