python绘制地图时_使用绘制地图时出现问题matplotlib.basemap

这篇博客讨论了在使用Python的`mpl_toolkits.basemap`模块绘制地图时遇到的错误:"RuntimeError: Can not put single artist in more than one figure"。作者分享了引发此问题的代码片段,并寻求解决方案。代码涉及从NOAA获取数据,创建Mercator投影地图,以及在地图上绘制雷达数据。
部署运行你感兴趣的模型镜像

这是我的Python代码。它曾经工作过一次,但在我更改了某些内容之后,我不记得我更改了什么,它现在返回以下错误:raise RuntimeError("Can not put single artist in " RuntimeError: Can

not put single artist in more than one figure

关于这个问题有什么帮助吗from mpl_toolkits.basemap import Basemap

import numpy as np

import matplotlib.pyplot as plt

import matplotlib as mpl

import numpy.ma as ma

import netCDF4

import os

import datetime

mydate='20181110' #(put today date)

myhour = '00' # in UTC timezone

url='http://nomads.ncep.noaa.gov:9090/dods/hrrr/hrrr%s/hrrr_sfc.t%sz' %(mydate,myhour)

print url

# make sure folder exists

folder_path = 'pcptype/%s/%sz' %(mydate,myhour)

if not os.path.exists(folder_path):

os.makedirs(folder_path)

# Read data

t = 10

file = netCDF4.dataset(url)

lat = file.variables['lat'][:]

lon = file.variables['lon'][:]

time = file.variables['time'][:]

rad_ref = file.variables['refcclm'][t,:,:]

#### plotting data

m=Basemap(projection='merc',lat_ts=0,llcrnrlon=-81.0, \

urcrnrlon=-66,llcrnrlat=41.0,urcrnrlat=49.0, resolution='i')

bounds_rain = [0,5,10,15,20,25,30,35,40,100]

bounds_ref = [10,25,30,35,40,100] cmap=mpl.colors.ListedColormap(['#99CCFF','#0099FF','#00FF66','#00CC00','#009900','#006600','#FFFF33','#FFCC00','#FF9900','#FF6600','#FF0000','#FF0299','#9933CC','#660099'])

xx,yy = np.meshgrid(lon,lat)

x,y =m(xx,yy)

m.drawstates()

m.drawcoastlines()

m.drawcountries()

m.drawmapboundary()

norm_ref = mpl.colors.BoundaryNorm(bounds_ref, cmap.N)

first_date = datetime.datetime(1,1,1,0,0,0)

init_datetime = first_date+ datetime.timedelta(time[0])

#for t in range(1, len(time)):

print 'processing time %i ' %t

fct_datetime = first_date + datetime.timedelta(time[t])

fig_name = 'pcp_type_%s' %(fct_datetime.strftime("%Y%m%d_%H00"))

print fig_name

fig=plt.figure(figsize=(10, 10))

map1=m.contourf(x, y, rad_ref,len(bounds_ref),norm=norm_ref,cmap=cmap,levels=bounds_rain)

plt.title("RADAR | Init : %s Valid: %s" \

%(init_datetime.strftime("%HZ %Y-%m-%d"),fct_datetime.strftime("%HZ %Y-%m-%d")),loc='left')

plt.savefig("%s/%s.png" %(folder_path,fig_name), dpi=200,bbox_inches='tight' )

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值