import numpy as np
import my_class
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
file = r"D:\lunwen\lunwenshuju\各种作业数据\H500.txt"
f = open(file, "r")
data = np.loadtxt(file, dtype=str,delimiter='\n')
lines = f.readlines()
dataset = []
for line in lines:
data = line.strip("\n")
data = data.split('\t')
dataset.append(data)
dataset = np.array(dataset)
a = np.zeros(48)
i = 0
b = 0
while i < 48:
a[i] = b
i = i+1
b = b+18
a = a.astype(int) # 化为整数
dataset = np.delete(dataset, a, axis=0)
# 删除空格
# 建立一个37*17*48的三维数组
hgt = np.zeros((17, 37, 48))
# 将二维变成三维
for k in range(48):
for i in range(17):
c = dataset[i][0]
c = c.replace(" ", "")
w = 6
for j in range(37):
hgt[i, j, k] = float(c[w-6:w])
w = w+6
Python 处理dat文件并画图
于 2022-10-17 17:58:30 首次发布