Each row in the dataset has three datapoints. How can I plot a line for each one, as indicated?
import matplotlib.pyplot as plt
import pandas as pd
from mpl_toolkits.mplot3d import Axes3D
dataset = pd.read_csv('data.csv')
X = dataset.iloc[:, 0:2].values
y = dataset.iloc[:, -1].values
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X[:, 0], X[:, 1], y, marker='.', color="red")
ax.set_xlabel("Cone")
ax.set_ylabel("Time")
ax.set_zlabel("Temp")
plt.show()
This is the data. SO wont let me save the post now that I have added the data because it says my question is mostly code, so I am writing this longwinded thing so that hopefully it lets me post. You can just ignore this paragraph. It is only here to balance out the code with prose so that Stack overflow will let me post.
cone,ramp,temp
4,15,1141
4,60,1162
4,150,1183
5,15,1159
5,60,1186
5,150,1207
6,15,1185
6,60,1222
6,150,1243
7,15,1201
7,60,1239
7,150,1257
8,15,1211
8,60,1249
8,150,1271
9,15,1224
9,60,1260
9,150,1280
10,15,1251
10,60,1285
10,150,1305
11,15,1272
11,60,1294
11,150,1315
12,15,1285
12,60,1306
12,150,1326
13,15,1310
13,60,1331
13,150,1348
14,15,1351
14,60,1365
14,150,1384
CodePudding user response:
One way is to loop over the unique values of the cone
column:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
for u in dataset["cone"].unique():
extracted_df = dataset[dataset["cone"] == u]
values = extracted_df.values
ax.plot(values[:, 0], values[:, 1], values[:, 2], color="red")
ax.set_xlabel("Cone")
ax.set_ylabel("Time")
ax.set_zlabel("Temp")
plt.show()