0

How can I plot a surface graph with Matplotlib (python), if I only have 3 lists (X, Y, Z)? I would also like to interpolate the rest of the values so that the graph area is completely filled. I've tried through similar answers found here, however, without success.

X = [925, 875, 840, 800, 775, 726, 689, 650, 626] #*seconds spent - dependent variable*

Y = [0.9960, 0.9680, 0.9600, 0.9540, 0.9525, 0.9510, 0.9420, 0.9365, 0.9300] #*accuracy - dependent variable*

Z = [600, 575, 550, 525, 500, 475, 450, 425, 400] #*size of dataset - the independent variable.*

I tried to use this:

from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import Rbf


x = [925, 875, 840, 800, 775, 726, 689, 650, 626]
y = [0.9960, 0.9680, 0.9600, 0.9540, 0.9525, 0.9510, 0.9420, 0.9365, 0.9300]
z = [600, 575, 550, 525, 500, 475, 450, 425, 400]

xnew = np.asarray(x)
ynew = np.asarray(y)
znew = np.asarray(z)

xi,yi = np.meshgrid(np.linspace(xnew.min(), xnew.max(), 10), np.linspace(ynew.min(), ynew.max(), 10))
    
rbf = Rbf(xnew, ynew, znew, funtion='cubic')
zi = rbf(xi, yi)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(xi,yi,zi,cstride=1,rstride=1,cmap='viridis')

And I obtained something like this (not the fully filled surface):

I know that I need to interpolate, but it's not working.

Surface plot

1 Answers1

0

Following Matplotlib's Gallery, you can use ax.plot_surface to plot a 3d surface using matplotlib. Just follow the example in the link.

See also the question here: surface plots in matplotlib. Which is the same solution as in the example above.

Roim
  • 2,986
  • 2
  • 10
  • 25
  • Thanks for your attentiton! I already saw this documents, but I need something less sophisticated, principaly, because I have only three lists (I don't have any functions from the data relationship). Can you help me, please? – Vinícius Wittig Vianna Sep 26 '20 at 14:09