python 根据经纬度绘制点图 极投影

参考了python cartopy手动导入地图数据绘制底图/python地图上绘制散点图:Downloading:warnings/散点图添加图里标签_python add_feature-CSDN博客

点的颜色按照时间显示

python 复制代码
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 13 11:32:48 2023

"""

import numpy as np
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import cartopy.feature as cfeature
import matplotlib.ticker as mticker
import matplotlib.path as mpath
import pandas as pd
from matplotlib.dates import date2num, DateFormatter
import matplotlib.dates as mdates

from matplotlib.colors import Normalize

# 转换时间格式r'C:\Users\Desktop\csv\all_files1min_nan.csv'
df = pd.read_csv(r'C:\Users\Desktop\csv\all_files_nan.csv')

df['time'] = pd.to_datetime(df['time'])

# 设置时间列为索引
df.set_index('time', inplace=True)

# 按小时计算平均值
df = df.resample('H').mean()

# 取消索引
df = df.reset_index()
df.dropna(axis=0, inplace=True)

fig = plt.figure(figsize=(12, 10),dpi=300)
proj =ccrs.NorthPolarStereo(central_longitude=0)#设置地图投影
#在圆柱投影中proj = ccrs.PlateCarree(central_longitude=xx)
leftlon, rightlon, lowerlat, upperlat = (-180,180,75,90)#经纬度范围

img_extent = [leftlon, rightlon, lowerlat, upperlat]

f1_ax1 = fig.add_axes([0.2, 0.3, 0.5, 0.5],projection = ccrs.NorthPolarStereo(central_longitude=0))#绘制地图位置

f1_ax1.set_extent(img_extent, ccrs.PlateCarree())
# f1_ax1.add_feature(cfeature.COASTLINE)
# f1_ax1.add_feature(cfeature.OCEAN)
# f1_ax1.add_feature(cfeature.LAND)
# 添加网格线和海岸线
# f1_ax1.gridlines(draw_labels=True)
f1_ax1.coastlines()
g1=f1_ax1.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1, color='gray',linestyle='--')
g1.xlocator = mticker.FixedLocator(np.linspace(-180,180,13))
g1.ylocator = mticker.FixedLocator(np.linspace(60, 90,4))


theta = np.linspace(0, 2*np.pi, 100)
center, radius = [0.5, 0.5], 0.44
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
circle = mpath.Path(verts * radius + center)
f1_ax1.set_boundary(circle, transform=f1_ax1.transAxes)

# 绘制极投影图
# plt.figure(figsize=(8, 8))

# 遍历DataFrame的行
for index, row in df.iterrows():
    # 将时间转换为数值
    time_value = date2num(row['time'])
    # 绘制散点,颜色按时间
    sc=f1_ax1.scatter(row['lon'], row['lat'], c=time_value, cmap='viridis', s=10,vmin=date2num(df['time']).min(), vmax=date2num(df['time']).max(),transform=ccrs.Geodetic())

# 添加colorbar
# 添加colorbar
cbar = plt.colorbar(sc, label='Date and Time')
# 将colorbar上的标签显示为日期和时间
date_format = mdates.DateFormatter('%b %d %Y') 
# %H:%M:%S
cbar.ax.yaxis.set_major_formatter(date_format)
# cbar.set_ticklabels(df['time'])
# 自定义日期格式化器

plt.show()
相关推荐
带娃的IT创业者13 分钟前
如何开发一个教育性质的多线程密码猜测演示器
网络·python·算法
luckys.one6 小时前
第9篇:Freqtrade量化交易之config.json 基础入门与初始化
javascript·数据库·python·mysql·算法·json·区块链
大翻哥哥7 小时前
Python 2025:量化金融与智能交易的新纪元
开发语言·python·金融
zhousenshan9 小时前
Python爬虫常用框架
开发语言·爬虫·python
IMER SIMPLE9 小时前
人工智能-python-深度学习-经典神经网络AlexNet
人工智能·python·深度学习
CodeCraft Studio9 小时前
国产化Word处理组件Spire.DOC教程:使用 Python 将 Markdown 转换为 HTML 的详细教程
python·html·word·markdown·国产化·spire.doc·文档格式转换
专注API从业者10 小时前
Python/Java 代码示例:手把手教程调用 1688 API 获取商品详情实时数据
java·linux·数据库·python
java1234_小锋10 小时前
[免费]基于Python的协同过滤电影推荐系统(Django+Vue+sqlite+爬虫)【论文+源码+SQL脚本】
python·django·电影推荐系统·协同过滤
看海天一色听风起雨落11 小时前
Python学习之装饰器
开发语言·python·学习
XiaoMu_00111 小时前
基于Python+Streamlit的旅游数据分析与预测系统:从数据可视化到机器学习预测的完整实现
python·信息可视化·旅游