How to find the centre of a 3D scatter plot?

71 Views Asked by At

I have been trying to plot the center of a 3D scatter plot and I am facing an issue determining the value for the z-value. I want the z axis value that puts the centre on the scatter plot. How to find the centre of a 3D scatter plot?

Here is what I have tried.

import xlrd
import numpy as np
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# axes = [5, 5, 5]
# Create Data
# data = np.ones(axes, dtype=np.bool)
df=pd.read_csv('wr.csv')
df=df.sample(frac=1)
# print(df.head())
fig = plt.figure()
#---------------1st plt-------------------------
ax = fig.add_subplot(projection='3d')
ax.scatter(df.index, df['volatile acidity'], np.ones(df.shape[0]), s=5,color='red')
ax.scatter(np.mean(df.index),np.mean(df['volatile acidity']),1,color='black',s=200)

Fig1 enter image description here

Now I wanted to try the same thing with a different approach and let the z-axis value change dynamically according to the scatter plot.

import xlrd
import numpy as np
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# axes = [5, 5, 5]
# Create Data
# data = np.ones(axes, dtype=np.bool)
df=pd.read_csv('wr.csv')
df=df.sample(frac=1)
# print(df.head())
fig = plt.figure()
#---------------1st plt-------------------------
ax = fig.add_subplot(projection='3d')
#ax.scatter(df.index, df['volatile acidity'], np.ones(df.shape[0]), s=5,color='red')
#ax.scatter(np.mean(df.index),np.mean(df['volatile acidity']),1,color='black',s=200)
ax.scatter(df.index, df['volatile acidity'], np.square(df['volatile acidity']), s=5,color='black')
ax.scatter(np.mean(df.index),np.mean(df['volatile acidity']),1,color='orange',s=20)

Here is the image for reference.

Fig2 enter image description here

0

There are 0 best solutions below