AlleyCat
AlleyCat

Reputation: 165

Plotting a Tuple in Python

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.

Upvotes: 0

Views: 1133

Answers (1)

Carson
Carson

Reputation: 8138

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

Upvotes: 1

Related Questions