python怎么导入ase3d,如何在Python中将图像正确地显示为具有步骤转换的3D绘图?...

最后终于回答了我自己的问题。在

解决这一问题的一种强力方法是重复数组中的值,从而使“matplotlib”所做的值之间的插值,影响更小,更接近阶跃变化。

这可以通过使用numpy.repeat来实现。由于这是一个三维数组,我们必须在一个轴上迭代,而不是在另一个轴上迭代。否则,将重复展平数组并返回此平面数组。在

结果:

OL4bX.pngdef ImPlot2D3D(img, cmap=plt.cm.jet, step=False, ratio=10):

if step:

img = (img.repeat(ratio, axis=0)).repeat(ratio, axis=1)

Z = img[::1, ::1]

fig = plt.figure(figsize=(14, 7))

# 2D Plot

ax1 = fig.add_subplot(1, 2, 1)

im = ax1.imshow(Z, cmap=cmap)

ax1.set_title('2D')

ax1.grid(False)

# 3D Plot

ax2 = fig.add_subplot(1, 2, 2, projection='3d')

X, Y = np.mgrid[:Z.shape[0], :Z.shape[1]]

ax2.plot_surface(X, Y, Z, cmap=cmap)

ax2.set_title('3D')

# Scale the ticks back down to original values

if step:

ticks_x = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x / ratio))

ticks_y = ticker.FuncFormatter(lambda y, pos: '{0:g}'.format(y / ratio))

ax1.xaxis.set_major_formatter(ticks_x)

ax1.yaxis.set_major_formatter(ticks_y)

ax2.xaxis.set_major_formatter(ticks_x)

ax2.yaxis.set_major_formatter(ticks_y)

plt.show()

import matplotlib.ticker as ticker

import matplotlib.pyplot as plt

import numpy as np

from mpl_toolkits.mplot3d import Axes3D

SubIm = np.load("Subtract_Image.npy")

ImPlot2D3D(SubIm, step=True)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值