1

I'm having trouble understanding a strange side effect of interpolating my data. I am plotting a 2D surface onto a 3D grid, this part works fine, however as soon as I tweaked it to include scipy.interpolate I get a strange glitch, (at least I think it is a glitch).

Below is an image of two plots, LHS is the original data, RHS the interpolated plot. As you can see I have rotated the RHS so that the similarities between the shapes are clear, but as a result the axis facing us is different;

On the left we see the original data, on the right the strangely interpolated data (I have rotated both of these extensively and I'm confident the symmetry in this view is not a coincidence, it looks too similar and they look too different when viewed at the same rotation)

To add interpolation to my code I followed the answer to this question: Smooth surface Plot with Pyplot

I'll also add my code before and after I added that bit, in the hope that there's something really obvious I've missed

ax = fig.add_subplot(111, projection='3d')

#y is the sin(beta-alpha) value, x is the tan(beta) value and z is the cross-section in fb
y = np.array(Y_list)
x = np.array(x_list)
X, Y = np.meshgrid(x, y)

zs = np.array(z_list)
Z = zs.reshape(Y.shape)
print(type(Z))
print(Z.shape)

ax.plot_surface(X, Y, Z)

plt.ylabel(r"$Sin(\beta - \alpha)$")
plt.xlabel(r"$Tan(\beta)$")

ax.zaxis.set_rotate_label(False)  # disable automatic rotation
ax.set_zlabel('Cross-section (pb)', rotation=90)

#this is the rotation bit
for angle in range(0, 360):
    ax.view_init(30, angle)
    plt.draw()
    plt.pause(.001)

(Obviously there is code beforehand importing everything such as numpy, scipy etc and getting the data, but this is untouched between the two versions)

y = np.array(Y_list)
x = np.array(x_list)

xstart = float(x[0])
xend = float(x[-1])
ystart = float(y[0])
yend = float(y[-1])
X, Y = np.mgrid[xstart:xend:10j, ystart:yend:22j]

zs = np.array(z_list)
#Z = zs.reshape(Y.shape)

#The following lines perform interpolation
tck = interpolate.bisplrep(X, Y, zs, s=0)
Znew = interpolate.bisplev(X[:,0], Y[0,:], tck)

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z)

plt.ylabel(r"$Sin(\beta - \alpha)$")
plt.xlabel(r"$Tan(\beta)$")

ax.zaxis.set_rotate_label(False)  # disable automatic rotation
ax.set_zlabel('Cross-section (pb)', rotation=90)

#this is the rotation bit
for angle in range(0, 360):
    ax.view_init(30, angle)
    plt.draw()
    plt.pause(.001)

I'm stumped and any help would be appreciated!

Ciara
  • 65
  • 5

0 Answers0