0

In python, what is the syntax that will let me plot a tuple such as

t = [(9,2,5),(3,6,4),(2,8,4)]

I am having trouble since there are three elements in each combination.

5
  • 1
    are you using some plotting library e.g. matplotlib? Commented Feb 25, 2019 at 20:36
  • What is form of your plot? Commented Feb 25, 2019 at 20:38
  • Yes, I am using matplotlib.pyplot Commented Feb 25, 2019 at 20:40
  • What do you mean by "plotting a tuple"? What should it look like if you plotted t on a piece of paper? Commented Feb 25, 2019 at 20:50
  • What is your desired output? A point in the 3-d space? Commented Feb 26, 2019 at 3:08

1 Answer 1

1

If your t means: (x,y,z) => (9, 3, 2), (2, 6, 8), (5, 4, 4)

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

data = [(9, 3, 2), (2, 6, 8), (5, 4, 4)]
x, y, z = data[0], data[1], data[2]
ax = plt.subplot(111, projection='3d')
total_point = len(data)
ax.scatter(x[:total_point], y[:total_point], z[:total_point], c='red')
ax.plot(x[:total_point], y[:total_point], z[:total_point], c='yellow')

ax.set_zlabel('Z')
ax.set_ylabel('Y')
ax.set_xlabel('X')
plt.show()

output: enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

I tried running that but then I get this error: "shape mismatch: objects cannot be broadcast to a single shape"
That's because scatter() requires the length of each variable to must be the same.
check your data. each tuple length must be the same.
the x,y,z variables point to the tuple slice position. :total_point returns the range of tuples in the list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.