Python画等高线

import matplotlib

matplotlib.use('Agg') 

import matplotlib.pyplot as plt
import numpy as np

# Load Data
radData = np.loadtxt('rad.txt')

# x
xData = list(radData[:,0])
x = list(set(xData))
x.sort(key=xData.index)

# y
yData = list(radData[:,1])
y = list(set(yData))
y.sort(key=yData.index)

# to X and Y
X, Y = np.meshgrid(y, x)

# z
z = radData[:,2]
Z = np.array(z)
Z = Z.reshape((len(x), len(y)))

# width and height
width = max(x) - min(x)
height = max(y) - min(y)

fig = plt.figure(figsize=(width,height))
ax = fig.add_subplot(1, 1, 1) 

# 填充等高线的颜色, 9是等高线分为几部分
plt.contourf(Y, X, Z, 9, alpha = 0.75, cmap = plt.cm.jet)
# 绘制等高线
C = plt.contour(Y, X, Z, 9, colors = 'black')
# 绘制等高线数据
plt.clabel(C, inline = True, fontsize = 10)

# 去除坐标轴
plt.axis('off')
plt.tick_params(axis='both', left='off', top='off', right='off', bottom='off', labelleft='off', labeltop='off',
                    labelright='off', labelbottom='off')

#pad_inches设置为-0.05是为了剪去白边
plt.savefig('rad.png', bbox_inches='tight', dpi=90, pad_inches=-0.05)

plt.show()



数据格式(rad.txt)

行坐标<SP>列坐标<SP>值


例如:

-15.000 -7.500 0.0000
-15.000 -7.400 0.0000
-15.000 -7.300 0.0000
-15.000 -7.200 0.0000
-15.000 -7.100 0.0000
-15.000 -7.000 0.0000
-15.000 -6.900 1.0000
-15.000 -6.800 1.0000
-15.000 -6.700 1.0000


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值