add: plots
This commit is contained in:
57
plot_sites.py
Normal file
57
plot_sites.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
# 读取数据
|
||||
df = pd.read_excel('MFP Regular Sites 2019.xlsx')
|
||||
|
||||
# 计算中心纬度,用于校正经纬度比例
|
||||
lat_center = df['latitude'].mean()
|
||||
# 经度在该纬度下的校正系数
|
||||
aspect_ratio = 1 / np.cos(np.radians(lat_center))
|
||||
|
||||
# 创建图形
|
||||
fig, ax = plt.subplots(figsize=(14, 10))
|
||||
|
||||
# 绘制散点图
|
||||
scatter = ax.scatter(df['longitude'], df['latitude'],
|
||||
c=df['Number of Visits in 2019'],
|
||||
cmap='viridis',
|
||||
s=100,
|
||||
alpha=0.7,
|
||||
edgecolors='black',
|
||||
linewidth=0.5)
|
||||
|
||||
# 设置等比例坐标轴(考虑纬度校正)
|
||||
ax.set_aspect(aspect_ratio)
|
||||
|
||||
# 添加颜色条
|
||||
cbar = plt.colorbar(scatter, ax=ax)
|
||||
cbar.set_label('Number of Visits in 2019', fontsize=10)
|
||||
|
||||
# 添加站点标签
|
||||
for idx, row in df.iterrows():
|
||||
ax.annotate(row['Site Name'].replace('MFP ', ''),
|
||||
(row['longitude'], row['latitude']),
|
||||
fontsize=6,
|
||||
alpha=0.7,
|
||||
xytext=(3, 3),
|
||||
textcoords='offset points')
|
||||
|
||||
# 设置标签和标题
|
||||
ax.set_xlabel('Longitude', fontsize=12)
|
||||
ax.set_ylabel('Latitude', fontsize=12)
|
||||
ax.set_title('MFP Regular Sites 2019 - Geographic Distribution', fontsize=14)
|
||||
|
||||
# 添加网格
|
||||
ax.grid(True, alpha=0.3)
|
||||
|
||||
# 调整布局
|
||||
plt.tight_layout()
|
||||
|
||||
# 保存图片
|
||||
plt.savefig('sites_map.png', dpi=150, bbox_inches='tight')
|
||||
print('图片已保存为 sites_map.png')
|
||||
|
||||
# 显示图形
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user