我有以下数据:
2
[-0.09891464 -0.09715325 -0.09410605 -0.09019411 -0.0860636 -0.08205132
-0.07875871 -0.07614547 -0.07443062 -0.07346302 -0.07298417 -0.07290273
-0.07287797 -0.07287593 -0.07287593] code_length
[-0.98949882 -0.97240346 -0.94268702 -0.90432065 -0.86363176 -0.82404481
-0.79160852 -0.76596087 -0.74920381 -0.73978155 -0.73512854 -0.73433788
-0.73409758 -0.7340778 -0.7340778 ] code_length
[-0.08209141 0.24530752 0.57179519 0.89738478 1.22269259 1.54813354
1.87437147 2.20121635 2.52864319 2.85637075 3.18420369 3.51207073
3.83993948 4.16780833 4.49567718] code_length
[0.09891464 0.09715325 0.09410605 0.09019411 0.0860636 0.08205132
0.07875871 0.07614547 0.07443062 0.07346302 0.07298417 0.07290273
0.07287797 0.07287593 0.07287593] code_length
[-0.98949882 -0.97240346 -0.94268702 -0.90432065 -0.86363176 -0.82404481
-0.79160852 -0.76596087 -0.74920381 -0.73978155 -0.73512854 -0.73433788
-0.73409758 -0.7340778 -0.7340778 ] code_length
[-0.08209141 0.24530752 0.57179519 0.89738478 1.22269259 1.54813354
1.87437147 2.20121635 2.52864319 2.85637075 3.18420369 3.51207073
3.83993948 4.16780833 4.49567718] code_length
print(len(pos_list))
print(streamline_x[0])
print(streamline_y[0])
print(streamline_z[0])
print(streamline_x[1])
print(streamline_y[1])
print(streamline_z[1])我想绘制它们,我想用负z分量来绘制它们。它提供了以下两个周期:
for i in range(len(pos_list)):
ax.plot3D(streamline_x[i], streamline_y[i], streamline_z[i], color=cfg._sections['colors'].get('mag_field'), linewidth=cfg._sections['styles'].get('lines'))
for i in range(len(pos_list)):
ax.plot3D(streamline_x[i], streamline_y[i], -streamline_z[i], color=cfg._sections['colors'].get('mag_field'), linewidth=cfg._sections['styles'].get('lines'))不过,我想简化一下,创建3个列表来绘制,而不是6个。我尝试了以下方法:
minus_streamline_z1 = []
minus_streamline_z2 = []
# Create a function that multiplies each element in list by (-1)
for x in streamline_z[0].tolist():
minus_streamline_z1.append(x * (-1))
for x in streamline_z[1].tolist():
minus_streamline_z2.append(x * (-1))
minus_streamline_z = [minus_streamline_z1, minus_streamline_z2]
# Adding symmetric parts of streamline to plot them
for i in range(len(pos_list)):
xs = streamline_x[i].tolist() + streamline_x[i].tolist()
ys = streamline_y[i].tolist() + streamline_y[i].tolist()
zs = streamline_z[i].tolist() + minus_streamline_z[i]
ax.plot3D(xs, ys, zs)请问出什么事了?
前两个周期给出了这个数字:

第二种方式给出了一些奇怪的线条

发布于 2020-08-24 19:45:40
问题是,您当前的第一个列表从(-0.09891464, -0.98949882, -0.08209141)开始,并在z方向上移到(-0.07287593, -0.7340778, 4.49567718)。当您将这两个列表连接在一起时,它会跳转到(-0.09891464, -0.98949882, 0.08209141),然后沿z方向向下移动到(-0.07287593, -0.7340778, -4.49567718)。
列表连接处的跳跃通向您在第二张图中看到的直线段。
要解决此问题,可以在将两个列表中的第一个列表连接到一起时颠倒它们的顺序(使用[::-1]对列表进行索引)。
例如:
for i in range(2):
xs = streamline_x[i].tolist()[::-1] + streamline_x[i].tolist()
ys = streamline_y[i].tolist()[::-1] + streamline_y[i].tolist()
zs = streamline_z[i].tolist()[::-1] + minus_streamline_z[i]
ax.plot3D(xs, ys, zs)产生:

请注意,当您从z=-0.08209141跳回到两个列表连接的z=0.08209141时,仍然有一个小的线性段,但对于这个特定的图,这似乎并不明显。
https://stackoverflow.com/questions/63558459
复制相似问题