Python 停止matplotlib 3D曲面打印,使其轴标签被切断
我正在写一段代码来模拟原子在电场和磁场中的相互作用。这部分要求我在给定的高度上绘制相互作用势的3D图。生成这些绘图的完整代码非常长,分为几个模块,但相关绘图部分为:Python 停止matplotlib 3D曲面打印,使其轴标签被切断,python,matplotlib,Python,Matplotlib,我正在写一段代码来模拟原子在电场和磁场中的相互作用。这部分要求我在给定的高度上绘制相互作用势的3D图。生成这些绘图的完整代码非常长,分为几个模块,但相关绘图部分为: # Function to plot 'PlotValues' at a height 'z' def Plot_AtHeight(self, PlotValues, z=500, ReturnFig=False, ShowTime=False): # Calls out to the relevant function
# Function to plot 'PlotValues' at a height 'z'
def Plot_AtHeight(self, PlotValues, z=500, ReturnFig=False, ShowTime=False):
# Calls out to the relevant function to calculate the values and return
# these as an array
PlotArray = self.Get_AtHeight(PlotValues, z)
pylab.rcParams.update( \
{'axes.labelsize': 18,
'text.fontsize': 18,
'xtick.labelsize': 18,
'ytick.labelsize': 18
})
fig = pylab.figure()
ax = Axes3D(fig)
# Make the arrays of the points at which the values are calculated
X, Y = np.mgrid[Xmin:Xmax:complex(0,Xpoints),
Ymin:Ymax:complex(0,Ypoints)]
ax.plot_surface(X, Y, PlotArray, cmap=cm.jet)
ax.set_xlabel('Position, x (nm)')
ax.set_ylabel('Position, y (nm)')
if PlotValues == 'B': ax.set_zlabel('Field Strength (G)', fontsize=18)
elif PlotValues == 'E': ax.set_zlabel('Field Strength (V/m)', fontsize=18)
elif PlotValues == 'U_Stark': ax.set_zlabel('Stark Interaction (J)', fontsize=18)
elif PlotValues == 'U_Zeeman': ax.set_zlabel('Zeeman Interaction (J)', fontsize=18)
elif PlotValues == 'U': ax.set_zlabel('Interaction Potential (J)', fontsize=18)
elif PlotValues == 'U_Stark_mK': ax.set_zlabel('Stark Interaction (mK)', fontsize=18)
elif PlotValues == 'U_Zeeman_mK': ax.set_zlabel('Zeeman Interaction (mK)', fontsize=18)
elif PlotValues == 'U_mK': ax.set_zlabel('Interaction Potential (mK)', fontsize=18)
# If we are not in a time averaged environment then display the current
# time (in ns) as the title to 1 decimal place.
if not self.TimeAveraged and ShowTime:
TimeStr = str(time*10**9)
try:
TimeTo1dp = '.'.join([TimeStr.split('.')[0], TimeStr.split('.')[1][0]])
except:
TimeTo1dp = TimeStr
ax.set_title("t = %sns" % TimeTo1dp, fontsize=18)
if not ReturnFig: pylab.show()
elif ReturnFig: return fig
此返回的绘图示例如下:
可以看到轴标签和记号有点乱。特别是,我希望有人知道如何阻止图像在底部被切断(即,使所有1000个图像都清晰)。我在很多角度都遇到了这个问题,有时轴标签被切断,有时记号被切断,但实际上python打开的用于查看和保存绘图的窗口似乎不够大,扩展它会缩放整个图像,因此标签/记号仍然被切断
任何帮助将不胜感激,请不要提及缩小字体大小或删除标签,因为这将进入报告,因此这些都是固定的
谢谢。您可以设置绘图的查看“距离”,例如
最大距离=13
默认值为10。