如何在 Python 中可视化空间农艺数据?
How to visualize spatial agronomical data in Python?
我是 python 的新手,我正在寻找一种方法来直观地表示我的字段值。就像网格热图。
我有一个 excel 文件(我用 pd.read_excel 导入),如下所示:
# X Y 分数
1 1 1 44
2 2 1 37
3 3 1 0
4 3 2 100
以此类推
Excel file
我知道有一种方法可以将 2d numpy 数组用于网格,但还没有找到如何使用我的 excel 文件。
我想要最后看起来像这样的东西
Output
有人可以帮我吗?
提前致谢
也回答了here. It uses the Excel's conditional formatting feature using Xlsx Writer. See here。
也许您正在寻找这样的东西(您可以根据需要更改颜色图):
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel('test.xlsx')
nrows = 2
ncols = 2
# Main Plot
score = np.array(df["Score"]).reshape(nrows,ncols)
plt.matshow(score,cmap=plt.cm.jet)
# Grid Labels
row_labels = range(1,nrows+1)
col_labels = range(1,ncols+1)
plt.xticks(range(ncols), col_labels)
plt.yticks(range(nrows), row_labels)
# Write Score
for i in range(ncols):
for j in range(nrows):
print(score[i,j])
plt.text(i, j, score[i,j], va='center', ha='center',color='white',size='20',weight='bold')
我是 python 的新手,我正在寻找一种方法来直观地表示我的字段值。就像网格热图。
我有一个 excel 文件(我用 pd.read_excel 导入),如下所示:
# X Y 分数
1 1 1 44
2 2 1 37
3 3 1 0
4 3 2 100
以此类推
Excel file
我知道有一种方法可以将 2d numpy 数组用于网格,但还没有找到如何使用我的 excel 文件。
我想要最后看起来像这样的东西
Output
有人可以帮我吗?
提前致谢
也回答了here. It uses the Excel's conditional formatting feature using Xlsx Writer. See here。
也许您正在寻找这样的东西(您可以根据需要更改颜色图):
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel('test.xlsx')
nrows = 2
ncols = 2
# Main Plot
score = np.array(df["Score"]).reshape(nrows,ncols)
plt.matshow(score,cmap=plt.cm.jet)
# Grid Labels
row_labels = range(1,nrows+1)
col_labels = range(1,ncols+1)
plt.xticks(range(ncols), col_labels)
plt.yticks(range(nrows), row_labels)
# Write Score
for i in range(ncols):
for j in range(nrows):
print(score[i,j])
plt.text(i, j, score[i,j], va='center', ha='center',color='white',size='20',weight='bold')