【发布时间】:2018-07-13 15:49:25
【问题描述】:
我有沿圆的直径以 1 毫米为增量的数据,即从 90 度开始到 270 度结束。我想以每 1 毫米的增量外推数据以填充圆的其余部分(在那个径向点)。例如:
10 毫米圆:
>Distance along diameter (mm) Value (a.u.)
>1 208
>5 210 (centre `(0,0)`)
>7 209
>10 208
现在我想要类似于:this image。在右侧带有图例/键并外推数据,以便径向数据点之间的过渡“平滑”。显然,实际上应该只需要一个半径值,但我希望直径中的另一半值来加强在第一个半径中观察到的值。
因此,我希望底部半径的值与沿直径从 180 度到 0 度的顶部半径值“混合”。这清楚吗?
我的初始(糟糕):
import numpy as np
import matplotlib.pyplot as plt
data = np.genfromtxt('data.txt',delimiter=',')
r = data[:,][:,0]
values = data[:,][:,1]
theta = np.zeros(len(data))
r, theta = np.meshgrid(r, theta)
plt.figure()
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
plt.show()
我了解ax.contourf 的输入必须是二维数组。但是,我的数据没有真正的 theta 值。我只想要一系列同心圆,所以我将我的数据修改为:
80,0,208.1790755
80,90,208.1790755
80,180,208.1790755
80,270,208.1790755
79,0,208.1322654
79,90,208.1322654
79,180,208.1322654
79,270,208.1322654
76,0,208.1804241
76,90,208.1804241
76,180,208.1804241
76,270,208.1804241
etc
我不明白为什么以下方法不起作用:
data = np.genfromtxt('data.txt',delimiter=',')
r = data[:,][:,0]
values = np.array(data[:,][:,2])
theta = np.radians(data[:,][:,1])
r, theta = np.meshgrid(r, theta)
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
plt.show()
【问题讨论】:
标签: python numpy matplotlib plot contour