将 3D 绘图保存在 python 中的正确位置

问题描述

我正在尝试将曲面图导出为 .png 文件。出于某种原因,保存图与 spyder 中显示的图的 3D 方向不对应。这是我的代码

import csv

import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import matplotlib as mpl
import numpy as np


with open(r'path','r') as f:
   voltpertime = list(csv.reader(f,delimiter=","))

voltpertime = np.array(voltpertime[0:],dtype=np.float)
Z= np.flipud(voltpertime)


fig,ax = plt.subplots(subplot_kw={"projection": "3d"})

# Make data.
X = np.arange(1,36,1)
Y = np.arange(-4,8,0.1)
X,Y = np.meshgrid(X,Y)


# Plot the surface.
norm = mpl.colors.normalize(vmin=-0.5,vmax=7)
surf = ax.plot_surface(X,Y,Z,cmap=cm.jet,linewidth=1,antialiased=False,norm=norm)

# Customize the z axis.
ax.set_zlim(-3,7)

ax.zaxis.set_major_locator(LinearLocator(4))

ax.zaxis.set_major_formatter('{x:.02f}')

plt.colorbar(surf,shrink=0.5,aspect=5,label='current (nA)',pad = 0.1)

plt.yticks((-4,-2,2,4,6,8),("8","6","4","2","0","-2","-4"))


# rotate the axes and update
for angle in range(160,360):
   ax.view_init(35,angle)
   plt.draw()
   plt.pause(.001)


fig.savefig(r'path',transparent = True,bBox_inches= 'tight',dpi=600,edgecolor= None)


plt.show()

这是 spyder 中的情节:

Fig1

这是我保存时的情节:

Fig2

我想准确地导出图在 spyder 中的显示方式。

有什么想法吗?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)