我正在编写一段代码来模拟原子在电场和磁场中的相互作用。其中一部分需要我在给定高度生成相互作用势的 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 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打开以查看和保存绘图的窗口似乎不够大,并且扩展它会缩放整个图像,因此标签/蜱虫仍然被切断。
任何帮助将不胜感激,请不要提及减小字体大小或删除标签,因为这将进入报告,因此这些已修复。
谢谢。