停止matplotlib 3D surface plot包含轴标签cu

2024-10-01 15:34:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一段代码来模拟原子在电场和磁场中的相互作用。其中一部分需要我在给定高度绘制出相互作用势的三维图。生成这些绘图的完整代码非常长,并且分为几个模块,但是相关的绘图部分是:

# 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 

返回的绘图示例如下:

one of the plots created

可以看到轴标签和记号有点乱。尤其是,我希望有人能知道如何阻止图像从底部被剪掉(即,这样1000个图像都是清晰的)。我在很多角度都有这个问题,有时轴标签被切断,有时记号,但实际上python打开用来查看和保存绘图的窗口似乎不够大,展开它会缩放整个图像,所以标签/记号仍然被切断。在

任何帮助将不胜感激,请不要提及减小字体大小或删除标签,因为这将进入一个报告,所以这些是固定的。在

谢谢。在


Tags: theto绘图标签axsetelifmk

热门问题