问题描述
我正在绘制航天器在其轨道上特定点的轨迹图。
我有一段代码可以在3dMatplotlib中生成3d线图(此处显示了mycode和图形的一部分(我将X,Y,Z内的点数大大减少到每个数组约20个)更容易简单地复制和粘贴,因为原理相同):
#
从mpl_toolkits.mplot3d.axes3d import px
导入matplotlib.pyplot从numpy import *
XdS = [14.54156005,14.53922242,14.53688586,14.53454823, 14.5322106,14.52987297,14.52753426,14.52519555,14.52285792,14.52051922,14.51818051,14.51584073,14.51350095,14.51116117,14.5088214,14.50648162,14.50414076,14.50179991,14.49945906,14.49711821] ,31.12345016、31.12229745、31.12114473、31.11999201、31.1188393、31.11768443、31.11652957、31.11537471、31.11421984、31.11306283、31.11190582、31.11074882、31.10959181、31.1084348]
ZdS = [3.94109446,3.94060316,3.94011186,3.93962083,3.93912926,3.93863796,3.93814639,3.93765482,3.93716325,3.93667169,3.93617985,3.93568828,3.93519618,3.93470434,3.9342125,3.9337204,3.93322829,3.93273b,3.932 $ b $ 3.9b b fig = plt.figure()
ax = fig.add_subplot(111,projection ='3d')
ax.plot(XdS,YdS,ZdS,c ='black',linewidth = 2)
ax.set_xlabel('XKSM(Saturn Radii)')
ax.set_ylabel('YKSM(Saturn Radii)')
ax.set_zlabel('ZKSM(Saturn Radii)')
plt.show()
#
我想做的是能够在此图的边缘/平面上绘制2d图X vs Y,X vs Z和Y vs Z,即显示3d轨迹在3 2d中的样子平面并将其显示在当前图的每个轴上。 (实际上并没有听起来那么复杂,因为我已经有了轨迹的X,Y,Z值)。在这里,我找到了一个类似的示例,它利用所有3d绘图功能来实现此目的,这些功能可从以下网址获得::如果您签出该链接,它将显示我尝试获得的图像类型。
从mpl_toolkits.mplot3d导入axes3d
导入matplotlib.pyplot as plt
从matplotlib导入cm
图= plt.figure()
轴= fig.gca(投影='3d')
X,Y,Z =轴3d.get_test_data(0.05)
ax.plot_surface(X ,Y,Z,rstride = 8,cstride = 8,alpha = 0.3)
cset = ax.contour(X,Y,Z,zdir ='z',offset = -100,cmap = cm.coolwarm)
cset = ax.contour(X,Y,Z,zdir ='x',offset = -40,cmap = cm.coolwarm)
cset = ax.contour(X,Y,Z,zdir ='y',offset = 40,cmap = cm.coolwarm)
ax.set_xlabel('X')
ax.set_xlim(-40,40)
ax。 set_ylabel('Y')
斧头set_ylim(-40,40)
斧头.set_ zlabel('Z')
ax.set_zlim(-100,100)
plt.show()
从理论上讲,这正是我所需要的,因为它采用了3d情况的平面视图。但是,我无法在3d轴上实现2d线图,也不能在2d图中使用offset命令(得到错误:TypeError:没有线属性 offset)。
是否有一个等效于3d offset命令的2d,是否可以根据需要在2d值的平面上绘制2d值?还有一种方法可以绘制已初始化3d投影的2d线?任何人都可以提出任何想法/总体上向我提出任何帮助以帮助我实现这一目标吗?订单,这是我的第一个订单!
尝试一下:
xmin = min(XdS)
ymax = max(YdS)
zmin = min(ZdS)
length_of_array = len(XdS)
xmin_array = [xmin] * length_of_array
ymax_array = [ymax] * length_of_array
zmin_array = [zmin] * length_of_array
fig = plt.figure()
ax = fig.add_subplot( 111,projection ='3d')
ax.plot(XdS,YdS,ZdS,zdir ='z',c ='r')
ax.plot(XdS,YdS,zmin_array,zdir = 'z',c ='g')
ax.plot(xmin_array,YdS,ZdS,'y')
ax.plot(XdS,ymax_array,ZdS,'b')
ax.set_xlabel('XKSM(Saturn Radii)')
ax.set_ylabel('YKSM(Saturn Radii)')
ax.set_zlabel('ZKSM(Saturn Radii)')
plt。 show()
I am producing plots of a spacecraft's trajectory at a specific point in its orbit.I have a piece of code which produces a 3d line plot in 3dMatplotlib (a part of mycode and figure is shown here (I have drastically reduced the number of points within X,Y,Z to ~20 per array to make it easier to simply copy and paste as the principle is the same):
#
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
from numpy import *
XdS=[14.54156005, 14.53922242, 14.53688586, 14.53454823, 14.5322106 , 14.52987297, 14.52753426, 14.52519555, 14.52285792, 14.52051922, 14.51818051, 14.51584073, 14.51350095, 14.51116117, 14.5088214 , 14.50648162, 14.50414076, 14.50179991, 14.49945906, 14.49711821]
YdS=[31.13035144, 31.12920087, 31.12805245, 31.12690188, 31.12575131, 31.12460073, 31.12345016, 31.12229745, 31.12114473, 31.11999201, 31.1188393 , 31.11768443, 31.11652957, 31.11537471, 31.11421984, 31.11306283, 31.11190582, 31.11074882, 31.10959181, 31.1084348]
ZdS=[3.94109446, 3.94060316, 3.94011186, 3.93962083, 3.93912926, 3.93863796, 3.93814639, 3.93765482, 3.93716325, 3.93667169, 3.93617985, 3.93568828, 3.93519618, 3.93470434, 3.9342125 , 3.9337204 , 3.93322829, 3.93273592, 3.93224382, 3.93175144]
fig=plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(XdS,YdS,ZdS,c='black',linewidth=2)
ax.set_xlabel('XKSM (Saturn Radii)')
ax.set_ylabel('YKSM (Saturn Radii)')
ax.set_zlabel('ZKSM (Saturn Radii)')
plt.show()
#
What I want to do is be able to plot the 2d plots X vs Y, X vs Z, and Y vs Z on the edges/planes of this plot i.e. show what the 3d trajectory looks like looking at it in the 3 2d planes and display them at each axis of the current plot. (It isn’t actually as complicated as it might sound, as I already have the X,Y,Z, values for the trajectory). Here I found a similar example which achieves this, however utilising all 3d plot functions, available at: http://matplotlib.org/1.3.1/examples/mplot3d/contour3d_demo3.html : If you check out check out the link it will show the type of image i am trying to achieve.
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)
plt.show()
This is in theory exactly what I need, in the way it takes sort of a planar view of the 3d situation. However I cannot implement a 2d line plot on a 3d axis nor can I use the offset command in a 2d plot (getting the error: TypeError: There is no line property "offset").
Is there a 2d equivalent to the 3d "offset" command and Is it possible to plot the 2d values on the planes of the 3d plot as I desire? Also is there a way to plot 2d lines having initialised a 3d projection? Can anyone offer any ideas/point me in any direction in general to help me achieve this?
My sincere thanks in advance and apologies if any part of this post is out of order, this is my first one!
Try this:
xmin = min(XdS)
ymax = max(YdS)
zmin = min(ZdS)
length_of_array = len(XdS)
xmin_array = [xmin] * length_of_array
ymax_array = [ymax] * length_of_array
zmin_array = [zmin] * length_of_array
fig=plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(XdS,YdS,ZdS,zdir='z', c='r')
ax.plot(XdS,YdS,zmin_array, zdir='z', c='g')
ax.plot(xmin_array, YdS, ZdS, 'y')
ax.plot(XdS,ymax_array,ZdS,'b')
ax.set_xlabel('XKSM (Saturn Radii)')
ax.set_ylabel('YKSM (Saturn Radii)')
ax.set_zlabel('ZKSM (Saturn Radii)')
plt.show()
这篇关于Matplotlib 2d图在3d图的面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!