Stop matplotlib 3D plot of surface from axes trimming

I am writing a piece of code that simulates the interaction of an atom in electric and magnetic fields. Part of this requires me to create 3D graphs of interaction potentials at a given height. The complete code for creating these graphs is very long and divided into several modules, however the relevant part of the graph is:

# 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 

      

An example of these graphs:

one of the plots created

You can see that the axis labels and ticks are a little messy. Specifically, I was hoping that someone might know how to stop clipping the image at the bottom (i.e. to keep all 1000s clear). I have this problem on a lot of angles, once the axis label is off, sometimes ticks, but essentially a python window opens to view and save the plot doesn't seem big enough and its extension scales the whole image so that the labels / ticks are still cut off.

Any help would be appreciated and please don't mention shrinking fonts or removing shortcuts as these are included in the report and are therefore fixed.

Thank.

+3


source to share


1 answer


You can set the "distance" to your plot, for example



ax.dist = 13

+3


source







All Articles