pandas - 将散点图作为熊猫数据框中的子图
问题描述
我有一个包含值、纬度、经度和年份变量的分组数据框。我想在地图上每年绘制不同位置的值。
This is how my dataframe looks:
from mpl_toolkits.basemap import Basemap
dtype: object
lat lon Date mean Year
0 2.912811 7.609220 2017-12-31 00:00:00+05:30 27.146307 2017
1 2.938906 7.697270 2017-12-31 00:00:00+05:30 19.067468 2016
这就是我在 4 个子图中绘制 2016 年至 2019 年数据的方法:df_yearly.dropna()
#Data to be shown on the map:
#fig = plt.figure(figsize=(6.5,9.0))
fig_title = 'Combined_map.pdf'
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 8))
year_start=2016
year_stop=2019
for i in range (1,5):
#for year in range(year_start, year_stop+1):
for year in df_yearly['Year']:
#print (year)
data = np.array(conc)
#create figure and axes instances
plot_location = '22'+ str(i)
print ('plot_location: '),
print (plot_location)
#plt.subplot(plot_location)
plt.tight_layout()
#create polar stereographic Basemap instance
m = Basemap(projection='mill',llcrnrlat=0,urcrnrlat=60,llcrnrlon=70,urcrnrlon=11, resolution='c')
# draw coastlines, state and country boundaries, edge of map.
m.drawcoastlines(linewidth =1.5, color ="black")
m.drawcountries(linewidth =1.5, color ="black")
m.drawmapboundary()
#Scatter:
m.scatter(lon, lat, latlon=True,c=np.array(conc),
cmap='jet', alpha=2)
# 3. create colorbar and legend
plt.colorbar(label=r'$Concentration$')
plt.clim(0, 200)
ptitle = "concentrations: "+str(year)
plt.title(ptitle, fontsize=7, weight='bold')
#plt.show()
plt.savefig(fig_title,bbox_inches="tight")
print ('Plotted:'), (fig_title)
如何将不同年份的值绘制在不同的散点图子图中?
解决方案
推荐阅读
- python - 如何从大型数据集中删除 NaN
- string - 使字符串看起来等长
- python - Ajax 调用后返回 python 脚本数据
- javascript - 如何使用 Jest/Enzyme 在反应组件中模拟来自 useContext() 的反应“调度”功能
- c# - 选择并计算行数
- javascript - 创建数组副本的JS问题
- python - 在 Python 中模拟重力的问题
- r - 过滤器不响应我闪亮的应用程序中的应用和清除按钮
- c++ - 投射`dlib::matrix的好方法
`进入`dlib::matrix` ? - java - java -cp 相对路径在 git-bash 上不起作用