0

I'm trying to use the scatter3D to plot in three dimensions. Create four subplots with the appropriate viewing angles using the view_init() function. So here's my code:

import pandas as pd

fileName = "MultipleLinearRegression.csv"
df = pd.read_csv("MultipleLinearRegression.csv")

%matplotlib tk from mpl_toolkits import mplot3d fig = plt.figure() ax = plt.axes(projection='3d') ax = Axes3D(fig)

#Subplot 1

fig = plt.figure(figsize=(4,4))
ax = fig.add_subplot(2,2,1, projection='3d')

ax.set_xlabel('x', c='r', size=14)
ax.set_ylabel('y', c='r', size=14)
ax.set_zlabel('z', c='r', size=14)

x_data = df['8.34044009405148']
y_data = df['9.58873988137183']
z_data = df['209.00852403785387']

ax.scatter3D(df['x_data'],df['y_data'],df['z_data'],cmap='jet')

ax.view_init(0, 90)

# displaying the plot
plt.show()

And here's the spreadsheet I'm pulling the data from:

x   y   z
8.34044009405148    9.58873988137183    209.00852403785400
14.406489868843200  13.64881572741860   325.4498177656920
0.0022874963468977300   0.5905816602662950  1.6517778449597900
6.046651452636800   6.3935107874857800  141.46490365671400
2.935117816342260   4.30215052053637    83.20450639846250
1.846771895375960   2.5204879701410000  47.51646541177870
3.725204227553420   2.4336415247549700  58.32325321483190
6.911214540860960   6.06297062581364    143.97075979727600

Here's the error message I'm getting:

UsageError: unrecognized arguments: from mpl_toolkits import mplot3d fig = plt.figure() ax = plt.axes(projection='3d') ax = Axes3D(fig)

And here's the outcome I'm wanting:

enter image description here

I've also tried:

%matplotlib tk from mpl_toolkits import mplot3d fig = plt.figure() ax = plt.axes(projection='3d') ax = Axes3D(fig)

x = 8.34044009405148, 15.00288629889935, 2.934571498116203, 7.953536739710671

y = 9.58873988137183, 16.691383353095627, 2.155464543082064, 8.860987900319106

z = 209.00852403785387, 378.2070301263841, 48.403467755855516, 196.816790498762
# creating the plot
plot_geeks = ax.scatter(x, y, z, cmap='jet')

# setting title and labels
ax.set_title("3D plot")
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.set_zlabel('z-axis')

# displaying the plot
plt.show()

Error:

UsageError: unrecognized arguments: from mpl_toolkits import mplot3

ax = plt.axes(projection='3d')
fig = plt.figure()
df.plot()  # plots all columns against index
df.plot(kind='scatter',x='x',y='y', z='z')

ax.scatter3D(xdata, ydata, zdata, c=zdata, cmap='jet');

Error:

AttributeError: PathCollection.set() got an unexpected keyword argument

So I'm not really sure where to go from here because the plots aren't working so I'm sure I'm just not getting it.

Kdoyle73
  • 91
  • 7

0 Answers0