I have made a 3D plot in Python using matplotlib and Axes3D. It looks pretty good, but it has a lot of jagged edges due to how much data I am plotting. I have tried scipy interpolation methods on the data, but the plot_surface
command does not like the type given back. I haven't been able to find out much else on the subject.
Here is my code so far:
import numpy
import scipy.io as sio
from matplotlib import pyplot
import matplotlib
from mpl_toolkits.mplot3d import Axes3D
import scipy
#data pulled from file
matFile = sio.loadmat(matFileLocation)
data = matFile['data']
[numrows, numcols] = numpy.shape(numpy.atleast_2d(data))
fig = pyplot.figure()
ax = fig.gca(projection = '3d')
x = range(numcols)
y = range(numrows)
X, Y = numpy.meshgrid(x,y)
hImage = ax.plot_surface(X,Y,data,cmap = 'jet', rstride = 1, cstride = 10, linewidth=0, antialiased = False)
fig.colorbar(hImage)
hImage.set_clim(mindb, maxdb)
pyplot.show()
Please note that x, y, and data will change based on different files I run. A point in the right direction would be much appreciated.
Edit: methods tried
I've tried so many different interpolation methods from too many different examples in the past two days that I can't remember what I have and haven't tried. I think I remember griddata
, interp2d
and some hImage.imshow(interpolation='gaussian')
(or something to that effect). Griddata returned something the plot_surface
couldn't understand, interp2d never finished and hImage turned my entire plot yellow with no scaled variations like I was expecting.
I have also tried other approaches like convolving my data with a 2D array of ones and dividing by the length of the 2D array. Unfortunately, my data contains a lot of very low values, so the few high values I have get lost in the convolution. Edit: I forgot to divide by len^2, the values make more sense now.
I am essentially looking for shading interp
from MatLab.