-1

我是 Python 的初学者。我相信 Python 会为 3D 等高线图完成这项任务。我有如下数据

Y/X (mm),   0,  10, 20, 30, 40
686.6,  -5.02,  -0.417, 0,  100.627,    0
694.08, -5.02,  -4.529, -17.731,    -5.309, -3.535
701.56, 1.869,  -4.529, -17.731,    -5.309, -3.535
709.04, 1.869,  -4.689, -17.667,    -5.704, -3.482
716.52, 4.572,  -4.689, -17.186,    -5.704, -2.51 
724,    4.572,  -4.486, -17.186,    -5.138, -2.51
731.48, 6.323,  -4.486, -16.396,    -5.138, -1.933
738.96, 6.323,  -4.977, -16.396,    -5.319, -1.933
746.44, 7.007,  -4.251, -16.577,    -5.319, -1.688
753.92, 7.007,  -4.251, -16.577,    -5.618, -1.688
761.4,  7.338,  -3.514, -16.78, -5.618, -1.207
768.88, 7.338,  -3.514, -16.78, -4.657, -1.207
776.36, 7.263,  -3.877, -15.99, -4.657, -0.822

任何帮助如何开始..

更新问题

(1) 正如您所看到的原始数据,它们分别在第一行第一列有 xlabel 和 ylabel。如果我使用numpy.loadtxt函数,如何拆分“xs”和“ys”?

data = numpy.loadtxt('131014-data-xy-conv-1.txt')

(2) 你有什么想法从 旋转矩阵 M x N 吗?

(3) linespace 有 start = -70 和 stop = 60,和 num = 60,你知道如何进行第 5 步吗?

contour = subplot.contourf(xs, ys, data, levels=numpy.linspace(-70, 60, 60))
4

1 回答 1

0

您可以使用matplotlib,即它的contourf功能:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy


xs = numpy.array([0,  10, 20, 30, 40])
ys = numpy.array([686.6, 694.08, 701.56, 709.04, 716.52,
    724, 731.48, 738.96, 746.44, 753.92, 761.4, 768.88, 776.36])

data = numpy.array([
    [-5.02,  -0.417, 0,  100.627,    0],
    [-5.02,  -4.529, -17.731,    -5.309, -3.535],
    [1.869,  -4.529, -17.731,    -5.309, -3.535],
    [1.869,  -4.689, -17.667,    -5.704, -3.482],
    [4.572,  -4.689, -17.186,    -5.704, -2.51],
    [4.572,  -4.486, -17.186,    -5.138, -2.51],
    [6.323,  -4.486, -16.396,    -5.138, -1.933],
    [6.323,  -4.977, -16.396,    -5.319, -1.933],
    [7.007,  -4.251, -16.577,    -5.319, -1.688],
    [7.007,  -4.251, -16.577,    -5.618, -1.688],
    [7.338,  -3.514, -16.78, -5.618, -1.207],
    [7.338,  -3.514, -16.78, -4.657, -1.207],
    [7.263,  -3.877, -15.99, -4.657, -0.822]])

fig = plt.figure()
subplot = fig.add_subplot(111, xlabel='$x$, mm', ylabel='$y$, mm')

contour = subplot.contourf(xs, ys, data, levels=numpy.linspace(-20, 120, 20))
subplot.set_xlim((xs[0], xs[-1]))
subplot.set_ylim((ys[0], ys[-1]))
fig.colorbar(contour)

fig.savefig('t.png')

结果

你可以在这里看到什么matplotlib是有能力的。

于 2013-10-12T10:02:01.267 回答