0

I have x1, y1, z1 coordinated at time t1 and I have x2, y2, z2 coordinates at time t2. I want to plot the graph for them.

I have all numpy arrays.

A = [[44.254  44.114  44.353  44.899  45.082] [-0.934  0.506  1.389  0.938  0.881] [44.864  45.225  44.005  42.981  46.356]]

t1 = [0 1.4911475447  1.5248639284  1.2450273089    3.3804382852]

B = [[44.254  48.4877582254 43.0268091866   47.3166368948   47.7110371397] [-0.934  1.0837036817    4.8307913511    6.2772868228    9.6580229826] [44.864   47.1020391758   43.0633715949   42.1564814645   42.0223003717]]

t2 = [0 0.00392157  0.00784314  0.01176471  0.01568627 ]

How can I plot these numpy arrays in graphs?

sam
  • 18,509
  • 24
  • 83
  • 116
  • 1
    What have you tried? Do you have a particular plotting library you would like to use? Matplotlib? Have you attempted to read any basic plotting tutorials in Python? – three_pineapples Jan 16 '14 at 05:17
  • @three_pineapples : yes I am reading Matplotlib but yet unable to understand how can I plot it – sam Jan 16 '14 at 05:18
  • @sam, do you want to plot them to 6 lines? – zhangxaochen Jan 16 '14 at 05:24
  • @zhangxaochen : I want to plot as many types of graphs I can from these data – sam Jan 16 '14 at 05:24
  • @sam, what do you mean by 'types'? at least give some specific types you want... – zhangxaochen Jan 16 '14 at 05:27
  • @zhangxaochen : for example 1 : A and B are the x, y, x coordinates. I want to show them with respect to time t1 and t2., example 2 : plotting A and B overlapping with respect to time. example 3 : showing 6 lines graph, etc – sam Jan 16 '14 at 05:30
  • @sam I suggest you read this question (http://stackoverflow.com/a/3872849/1994235 ), which details a bunch of good tutorials, specifically http://wiki.scipy.org/Cookbook/Matplotlib/ and come back when you have a specific problem with some code you have tried. The question as it stands is far to broad to be sufficiently answered here. – three_pineapples Jan 16 '14 at 05:45
  • @three_pineapples : I have created 3 plots for every coordinates for A and B. I want to show x, y and z coordinates in one graph only for A and B. how can I show that? – sam Jan 16 '14 at 06:20

2 Answers2

2

if you want to show the 3d displacement of A, B, use module mpl_toolkits.mplot3d

A = [[44.254, 44.114, 44.353, 44.899, 45.082],[-0.934, 0.506, 1.389, 0.938, 0.881],[44.864, 45.225, 44.005, 42.981, 46.356]]
t1 = [0, 1.4911475447, 1.5248639284, 1.2450273089, 3.3804382852]
B = [[44.254, 48.4877582254, 43.0268091866,  47.3166368948,  47.7110371397], [-0.934, 1.0837036817, 4.8307913511, 6.2772868228, 9.6580229826],  [44.864,  47.1020391758,  43.0633715949,  42.1564814645,  42.0223003717]]
t2 = [0, 0.00392157, 0.00784314, 0.01176471, 0.01568627 ]

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D
ax3d=plt.gca(projection='3d')
ax3d.plot(A[0], A[1], A[2], 'r',)
ax3d.scatter(A[0], A[1], A[2], c='r')

ax3d.plot(B[0], B[1], B[2], 'g',)
ax3d.scatter(B[0], B[1], B[2], c='g')

plt.show()

the plot result is as below: enter image description here

if you want to add an annotation to mark the start point of A, B, see question post

Community
  • 1
  • 1
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
1

Based on your comment:

I have created 3 plots for every coordinates for A and B. I want to show x, y and z coordinates in one graph only for A and B. how can I show that?

I believe what you are looking for is this:

A = [[44.254, 44.114, 44.353, 44.899, 45.082],[-0.934, 0.506, 1.389, 0.938, 0.881],[44.864, 45.225, 44.005, 42.981, 46.356]]
t1 = [0, 1.4911475447, 1.5248639284, 1.2450273089, 3.3804382852]
B = [[44.254, 48.4877582254, 43.0268091866,  47.3166368948,  47.7110371397], [-0.934, 1.0837036817, 4.8307913511, 6.2772868228, 9.6580229826],  [44.864,  47.1020391758,  43.0633715949,  42.1564814645,  42.0223003717]]
t2 = [0, 0.00392157, 0.00784314, 0.01176471, 0.01568627 ]

for i in range(len(A)):
    figure(1)
    plot(t1,A[i],'o')
    #figure(2)
    plot(t2,B[i],'o')
show()

Note that figure(x) sets the current figure to x or creates it if it doesn't exist. The plot function takes the form plot(x,y,'marker_style') where 'marker_style' is a string as defined here

three_pineapples
  • 11,579
  • 5
  • 38
  • 75
  • that is nice example but in this example, I can see 2 graphs. I need one graph in which I can see the differences between A and B – sam Jan 16 '14 at 07:17
  • @sam that was not made clear in your question (I interpreted what you said as one graph for A and one graph for B). Just comment out the line that reads `figure(2)` and you will see a single graph with 6 lines on it. – three_pineapples Jan 16 '14 at 07:28
  • ya I understood method how u did that and thanks for it. in your code, I can see 2 graphs, one for A and one for B. I want to plot only one graph which will contains A and B – sam Jan 16 '14 at 07:31
  • @sam as I said in my last comment, if you comment out the line that says `figure(2)` **you will get only one graph**. I've updated the code to show what I mean. – three_pineapples Jan 16 '14 at 11:05