- 积分
- 5917
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2017-3-7
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
- #Python画后向轨迹
- import numpy as np
- import matplotlib.pyplot as plt
- from mpl_toolkits.basemap import Basemap
- import cmaps
- from matplotlib.collections import LineCollection
- from pandas.core.frame import DataFrame
- file_path='1.txt'
- f = open(file_path)
- data = []
- for line in f.readlines():
- row = [] # 记录每一行
- lines = line.strip().split("\t")
- for x in lines:
- row.append(x)
- data.append(row)
- f.close()
- print(data[1][9])
- #data is list can not be writen data[1,9]
- newdata=DataFrame(data)#list tranform to dataframe
- fig, ax = plt.subplots()
- #fig=plt.figure(figsize=(25,7))
- m = Basemap(projection='spstere',boundinglat=-60,lon_0=180,resolution='l')
- m.drawcoastlines(linewidth=0.2, color='gray',zorder=3)
- #m.drawparallels(np.arange(-90.,-50.,10.))
- # labels = [left,right,top,bottom]
- #m.drawmeridians(np.arange(-180.,180.,45.))
- parallels = np.arange(-90,-50,10) #纬线
- m.drawparallels(parallels,labels=[False,False,False,False])
- #plt.yticks(parallels,len(parallels)*[''])
- meridians = np.arange(-180,180,45) #经线
- m.drawmeridians(meridians,labels=[False,False,True,True])
- cmap=cmaps.WhiteBlueGreenYellowRed
- lon = newdata[:][2]
- lat = newdata[:][3]
- #h是高度值
- h = newdata[:][4]
- points = np.array([lon, lat]).T.reshape(-1, 1, 2)
- segments = np.concatenate([points[:-1], points[1:]], axis=1)
- print(segments)
- norm = plt.Normalize(0, 1200)
- #设置颜色线条
- lc = LineCollection(segments, cmap=cmap,norm=norm)
- lc.set_array(h)
- #绘制线条
- line = ax.add_collection(lc)
- #colorbar
- fig.colorbar(line)#方向
- plt.show()
- plt.savefig('traj.png',dpi=600)
复制代码- resdat -= vmin
- TypeError: unsupported operand type(s) for -: 'str' and 'float'
复制代码
上面是报错类型,感觉是我把数据存为数据框类型,变成了series类型,搞了四个小时还没解决!求助!谢谢!
|
-
-
1.txt
5.55 KB, 下载次数: 6, 下载积分: 金钱 -5
|