我正在使用圆柱坐标,创建了inputFileName = 'input.csv'
outputFileName = 'output.csv'
with open(inputFileName, 'rb') as inFile, open(outputFileName, 'wb') as outfile:
r = csv.reader(inFile)
w = csv.writer(outfile)
table = list(r)
w.writerow(table[0])
# Winter
for line in table:
if line[4] == '2' or line[5] == '2' or line[6] == '2':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '2', line[8], line[9]))
elif line[4] == '4' and line[5] == '4' and line[6] == '10':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '4', line[8], line[9]))
elif line[4] == '4' and line[5] == '10' and line[6] == '10':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '4', line[8], line[9]))
elif line[4] == '10' and line[5] == '4' and line[6] == '10':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '10', line[8], line[9]))
elif line[4] == '10' and line[5] == '10' and line[6] == '4':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '10', line[8], line[9]))
elif line[4] == '10' and line[5] == '4' and line[6] == '4':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '10', line[8], line[9]))
elif line[4] == '10' and line[5] == '10' and line[6] == '10':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '10', line[8], line[9]))
elif line[4] == '4' and line[5] == '4' and line[6] == '4':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], '4', line[8], line[9]))
# Summer
for row in table:
if line[1] == '2' or line[2] == '2' or line[3] == '2':
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7], '2', line[9]))
else:
w.writerow((line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7], '10', line[9]))
并尝试使用meshgrid
绘图。我的完整数据集无法正确绘制,因为Y轴上的缩放不正确。
我正在尝试绘制磁场值与plot_surface
和Z
(rho)值的关系。 P
可以是消极的和积极的。 Z
(rho)只能是积极的。
问题在于P
(Y轴)总是从p
开始到0
(给10
),而我想让它像:{ {1}}以便以0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
为中心。
所以这是我的示例代码。我不会添加磁场的计算。这些与此问题无关。
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
所以在添加行时,
0
维度被破坏,fig = plt.figure()
ax = Axes3D(fig)
# Define the plane over which fields are computed.
# N must be odd to include the point (0,0).
M = 26 # No. of points along the rho axis.
N = 51 # No. of points along the z axis.
p1 = np.linspace(0, a, M)
p = np.concatenate([p1[::-1][:-1], p1]) # Make it symmetric.
z = np.linspace(-d, d, N)
p, z = np.meshgrid(p, z) # Create grid of (p,z).
# CALCULATE magnetic field bt. So assume this is done here...
bt = np.sqrt(np.power(bz, 2) + np.power(bp, 2))
ax.plot_surface(z, p, bt, cmap=plt.cm.YlGnBu_r)
plt.show()
正在抱怨。我希望这条线会将0放在数组中间。
感谢。