How to build a multidimensional function in Python?

Building a single function variable in Python is pretty simple with matplotlib . But I'm trying to add a third axis to the scatter plot so that I can visualize my multidimensional model.

Here is an example snippet with 30 outputs:

 import numpy as np np.random.seed(2) ## generate a random data set x = np.random.randn(30, 2) x[:, 1] = x[:, 1] * 100 y = 11*x[:,0] + 3.4*x[:,1] - 4 + np.random.randn(30) ##the model 

If it were just one model variable, I would probably use something like this to create a graph and a line of best fit:

 %pylab inline import matplotlib.pyplot as pl pl.scatter(x_train, y_train) pl.plot(x_train, ols.predict(x_train)) pl.xlabel('x') pl.ylabel('y') 

What is equivalent to multidimensional rendering?

+5
source share
3 answers

The most common approach is to change the color and / or size of the scatter symbols. For instance:

 import numpy as np import matplotlib.pyplot as plt np.random.seed(2) ## generate a random data set x, y = np.random.randn(2, 30) y *= 100 z = 11*x + 3.4*y - 4 + np.random.randn(30) ##the model fig, ax = plt.subplots() scat = ax.scatter(x, y, c=z, s=200, marker='o') fig.colorbar(scat) plt.show() 

enter image description here

+4
source

You can use mplot3d . For a scatter plot, you can use something like

 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(xs, ys, zs) 
+4
source

All Articles