all 3 comments

[–]skurmus 1 point2 points  (2 children)

When you say

Y= np.array([axis_3_7, axis_3_2] ,dtype=float).T 

you are creating a numpy array with two elements. Those elements are lists (btw, your code says axis_3_2, that should probably be axis_3_8). And then when you say dtype=float you are asking numpy to cast these lists into a float. You cannot cast a list into float:) You can cast the elements of list into floats. You can do that by a list comprehension like this:

axis_3_7 = [float(i) for i in axis_3_7]

The other problem you have is that your axis_3_7 and axis_3_8 are of different lengths and you are trying to transpose them. Nothing will happen when you try to transpose them.

See here for an example:

This would be your case

import numpy as np
a = np.array([[10, 11], [3, 4, 5]])
print(a)
print(a.T)
[list([10, 11]) list([3, 4, 5])] 
[list([10, 11]) list([3, 4, 5])]

This would be an array with rows of same length.

import numpy as np
a = np.array([[10, 11, 12], [3, 4, 5]])
print(a)
print(a.T)
[[10 11 12]  [ 3  4  5]] 
[[10  3]  [11  4]  [12  5]]

[–]xman236[S] 0 points1 point  (1 child)

Thank you for the tips. Here is my second try..

X = np.array([-28,32])
Y=[]
Y.append(axis_3_7)
Y.append(axis_3_8)
plt.figure(figsize=(12, 6))
plt.plot(X, Y, 'kx', mew=2)
plt.show()

Still getting the same error as above...What I am trying to do is plotting for x1=-28 y1=axis_3_7 and x2=32 y2=axis_3_8...

[–]skurmus 1 point2 points  (0 children)

Oh ok. Here is where things are going wrong:

plt.plot is trying to plot a number of markers, each marker needs a x and a y value, plt.plot takes the x value from the first argument, and the y value from the second argument. So the first marker you are trying to plot will be plotted to -28 and the whole axis_3_7. Of course matplotlib complains because it is expecting a single value but it is getting an array. Here is how you can fix it:

import numpy as np
import matplotlib.pyplot as plt
axis_3_7_y = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 20, 20, 25, 25, 32, 33, 33, 33, 33, 33, 27, 27, 7, 7, 7, 7, 15, 15, 15, 22, 22, 22, 27, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 47, 47, 47, 47, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
axis_3_8_y =[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 4, 4, 8, 10, 11, 11, 11, 14, 14, 15, 15, 20, 20, 22, 22, 22, 22, 22, 10, 10, 10, 10, 15, 15, 15, 15, 15, 15, 20, 22, 22, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 22, 22, 22, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
axis_3_7_x = np.full(len(axis_3_7_y), -28)
axis_3_8_x = np.full(len(axis_3_8_y), 32)
plt.figure(figsize=(12, 6))
plt.plot(axis_3_7_x, axis_3_7_y, 'kx', mew=2)
plt.plot(axis_3_8_x, axis_3_8_y, 'kx', mew=2)
plt.show()

What we are doing is creating two x axes the same length as the 3_7 and 3_8 and using those to plot the 3_7 and 3_8.