title: Move 3D plot to avoid clipping by margins
body: <p>I'm trying to figure out how I can get the 3D matplotlib images below to plot higher on the canvas so it doesn't get clipped. Here is the code I'm using to create the plot. I couldn't find a way to attach the text file containing the Z elevations (referenced in the code below), but it is simply a 2D array containing a surface made up of values ranging between 0 and 1.</p>
  
  <pre><code>import os
  import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.cm as cm
  from mpl_toolkits.mplot3d import Axes3D
  
  nrow=30
  ncol=100
  
  f = open(r'C:\temp\fracEvapCume_200.txt','r')
  fracEvapTS = np.loadtxt(f)
  f.close()
  
  X, Y = np.meshgrid(ncol, nrow)
  Y3d, X3d = np.mgrid[0:Y, 0:X]
  
  fig = plt.figure()
  ax = fig.gca(projection='3d')
  ax.auto_scale_xyz([0, 100], [0, 30], [0, 0.2])
  Y3d, X3d = np.mgrid[0:Y, 0:X]
  Z = fracEvapTS
  
  surf = ax.plot_surface(X3d, Y3d, Z, cmap='autumn', cstride=2, rstride=2)
  ax.set_xlabel("X-Label")
  ax.set_ylabel("Y-Label")
  ax.set_zlabel("Z-Label")
  ax.pbaspect = [1., .33, 0.25]
  ax.dist  = 7
  plt.tight_layout()
  plt.savefig('clipped.png')
  </code></pre>
  
  <p>In order to get the <code>ax.pbaspect=[1., .33, 0.25]</code> line to work, changes to the <code>get_proj</code> function inside site-packages\mpl_toolkits\mplot3d\axes3d.py were made as suggested in <a href="https://stackoverflow.com/questions/10326371/setting-aspect-ratio-of-3d-plot">this post</a>. In order to get the figure to draw larger, I added <code>ax.dist = 7</code> based on <a href="https://stackoverflow.com/questions/4962442/axes3d-data-labels-and-plot-limits">this post</a>. Lastly, based on <a href="https://stackoverflow.com/questions/4042192/reduce-left-and-right-margins-in-matplotlib-plot">this post</a> I was hoping that <code>plt.tight_layout()</code> would roll back the margins and prevent the red/yellow surface shown below from being clipped, but that didn't work either. I'm failing to find the command that will move the image up on the canvas, thereby avoiding all of the unnecessary white space at the top of the figure and preventing the red/yellow surface from getting clipped. Is there one line of Python that will accomplish this?</p>
  
  <p><a href="https://i.stack.imgur.com/T0NiA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T0NiA.png" alt="enter image description here"></a></p>
  
  <p>after adding the line <code>plt.tight_layout()</code>, it made matters worse:</p>
  
  <p><a href="https://i.stack.imgur.com/Eoud1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Eoud1.png" alt="enter image description here"></a></p>