如何使用二维数据数组创建密度或热图?
我需要一些帮助来制作带有纬度/经度坐标的密度/热图。我已经能够在地图上单独绘制这些点(见下文),但需要查看密度。
这是我的代码。
import pandas as pd
import geopandas
import matplotlib.pyplot as plt
import scipy
from scipy import io
df = pd.read_csv("/data.csv")
df_lightning = pd.DataFrame(
{'Latitude': df['LAT'],
'Longitude': df['LON']})
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
usa = geopandas.read_file('path/states.shp')
counties = geopandas.read_file('path/Tx_CntyBndry_Detail_TIGER500k.shp')
ax = usa.plot(color='white', edgecolor='black')
plt.plot(df_lightning.Longitude, df_lightning.Latitude, '.')
ax.set_ylim(25, 30)
ax.set_xlim(-98, -91)
plt.ylabel('Latitude (deg)', fontsize = 14)
plt.xlabel('Longitude (deg)', fontsize = 14)
plt.title('Source Locations of Combined TCs', fontsize = 16)
这是我制作的情节:
这就是我的数据框的样子。仅使用纬度和经度:
关于我可以尝试制作密度图的任何建议吗?我尝试过 countourf、pcolor、pcolormesh 等,但它们都需要第三个维度来绘制。有没有办法不用这个?我对编码还是新手,所以欢迎任何帮助。谢谢!
CSV 文件链接:https://drive.google.com /file/d/1fPRhgBXTlULmsFcRV-3ivkxlRSD_bGVa/view?usp=sharing 说明使用的 .shp 文件:https://drive.google.com/文件/d/1uWTbVONNq08d6LrPGBNkpikFBEX9AJQn/view?usp=sharing
I need some help making a density/heatmap with lat/long coordinates. I've been able to plot these points by themselves on a map (see below), but need to see the density.
Here is the code I have.
import pandas as pd
import geopandas
import matplotlib.pyplot as plt
import scipy
from scipy import io
df = pd.read_csv("/data.csv")
df_lightning = pd.DataFrame(
{'Latitude': df['LAT'],
'Longitude': df['LON']})
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
usa = geopandas.read_file('path/states.shp')
counties = geopandas.read_file('path/Tx_CntyBndry_Detail_TIGER500k.shp')
ax = usa.plot(color='white', edgecolor='black')
plt.plot(df_lightning.Longitude, df_lightning.Latitude, '.')
ax.set_ylim(25, 30)
ax.set_xlim(-98, -91)
plt.ylabel('Latitude (deg)', fontsize = 14)
plt.xlabel('Longitude (deg)', fontsize = 14)
plt.title('Source Locations of Combined TCs', fontsize = 16)
Here is the plot I've made:
This is what my dataframe looks like. Only using Lat and Lon:
Any suggestions on what I could try to make a density plot? I've tried countourf, pcolor, pcolormesh amongst others, but they all require a third dimension to plot with. Is there a way to do without this? I'm still new to coding so any help is welcomed. Thanks!
Link to csv file: https://drive.google.com/file/d/1fPRhgBXTlULmsFcRV-3ivkxlRSD_bGVa/view?usp=sharing
States .shp file used: https://drive.google.com/file/d/1uWTbVONNq08d6LrPGBNkpikFBEX9AJQn/view?usp=sharing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论