python - Scipy.interpolate 和 matplotlib 中的 3D 表面 - 数据似乎在轴内旋转?
问题描述
我无法理解插值数据的奇怪副作用。我正在将 2D 表面绘制到 3D 网格上,这部分工作正常,但是一旦我调整它以包含 scipy.interpolate 我就会遇到一个奇怪的故障(至少我认为这是一个故障)。
下面是两个图的图像,LHS 是原始数据,RHS 是插值图。正如你所看到的,我已经旋转了 RHS,这样形状之间的相似性就很明显了,但结果是面向我们的轴是不同的;
(我已经广泛旋转了这两个,我相信这个视图中的对称性不是巧合,它看起来太相似了,当在相同的旋转中查看时它们看起来太不同了)
为了在我的代码中添加插值,我遵循了这个问题的答案: Smooth surface Plot with Pyplot
我还将在添加该位之前和之后添加我的代码,希望有一些我错过的非常明显的东西
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)
(显然,事先有代码导入 numpy、scipy 等所有内容并获取数据,但这在两个版本之间保持不变)
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)
我很难过,任何帮助将不胜感激!
解决方案
推荐阅读
- javascript - jQueryUI datepicker 第二天的亮点
- sql - Presto Sql中如何按不同条件查找多个类别的日期?
- c# - C# 从字符串中获取属性名称
- ios - 无法触摸包含 AVPlayerLayer 的 UIView
- google-bigquery - 为什么 Parquet 文件中的数据在 BigQuery 表中加载后与源数据不匹配
- jquery - 如何根据其他“选择”框中的选定选项设置“选择”框的下拉值
- node.js - MongoDB 引用的集合。创建不生效
- html - CSS“计算”功能在 Internet Explorer 11 中无法按预期工作
- node.js - 节点 puppeteer 在最终页面着陆后生成 cookie(所有重定向完成后)
- mysql - 试图将 zonji 连接到远程数据库