0

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!

Chuck
  • 3,664
  • 7
  • 42
  • 76
  • So that I'm clear, you're problem is that you can do this with a "contour" plot but you don't want to use a contour plot? Isn't the projection onto these axis exactly x vs. y, y vs. z etc...? – Adam Hughes Nov 18 '14 at 17:29
  • Hi Adam. You are correct, the projection onto the axes is exactly as you say. My problem is getting them there in the first place. The extra example I included was used to show three 2d plots around a central 3d plot function (please excuse my awful python nomenclature), the contour plots work because it is still a 3d ready function (i think). This is how I would like mine to be however I cannot understand how to do a 2d plot within a 3d matplotlib figure/ moving what is there. – Chuck Nov 18 '14 at 18:08
  • Actually I think I have just found a simple workaround. For example on the x vs y 2d plot, I could plot it as 3d and set z fixed = to the value at relevant axis edge. This should give a 2d presentation I think.... Will have a go in a jiff! Thanks Adam! – Chuck Nov 18 '14 at 18:10

1 Answers1

2

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()

enter image description here

Kirubaharan J
  • 2,255
  • 16
  • 23
  • Thanks for the thoughts, I had thought to use max actually bit min works great too. Its much simpler this way than what i was trying to do. – Chuck Nov 19 '14 at 18:58
  • 1
    if you are ok with my answer, then you can click the tick mark – Kirubaharan J Nov 20 '14 at 06:05
  • I would love to and have tried, but because im so new, I need 15 feedback before I can even tick up :/ Sorry!! – Chuck Nov 20 '14 at 09:44
  • Just tried again and no luck :( When I have 15 feedback I shall return. – Chuck Nov 25 '14 at 14:16