Matplotlib surface plot unintuitive triangulation

Viewed 409

I have the following code that produces a surface plot, but it does not do what I would expect.

xx, yy = np.meshgrid(dealer_sums, player_sums)
    def getter(dealer_sum, player_sum):
        state = (dealer_sum, player_sum)
        return self.get_value(state)
    z = np.vectorize(getter)
    zz = z(xx,yy)

    fig = plt.figure()
    ax  = fig.add_subplot(111, projection='3d')
    ax.plot_wireframe(xx,yy, zz)

FYI, the shapes of xx, yy, and zz are all equal and 2D.

From looking at other posts about this (surface plots in matplotlib; Simplest way to plot 3d surface given 3d points) it looks like a common problem is that the x and y coordinates are irregular, but if I have understood correctly, I think mine are already regularised through the call to np.meshgrid?

I have provided a scatter plot below to show what the data looks like without surfaces: enter image description here

and this is what the call to plot_wireframe looks like:
enter image description here I have drawn over a few of the lines that I did not expect. My question is, is it possible to get rid of those lines and create a surface that looks like this? enter image description here

Thanks for your help.

EDIT: Here is a scatter plot of the XY grid, showing that it is regular: enter image description here

1 Answers
Related