2

How can a overlapping of labels and ticks be avoided when using matplotlib 3d plots?

The code below produces a matplotlib- figure. This figure shows a problem with labelpadding and 3D plots when using LaTeX in the labels. (Maybe someone with enough rights can post a corresponding figure)

There is a solution if one does not uses LaTeX in the label: Adjust label positioning in Axes3D of matplotlib

If you use LaTeX for rendering the label then a \n at the beginning is ignored (or produces errors)! I have tried a lot from \phantom and \vspace*, from \mbox to minipage, but it does not work! Is there any solution for mplot3d + x,y,zlabel + LaTeX

In the mplot3d API docu (http://matplotlib.org/mpl_toolkits/mplot3d/api.html) is mentioned, that the parameter labelpad is not jet implemented 'Currently, labelpad does not have an effect on the labels.'.

Example:

import matplotlib.pyplot as pyplot  
import mpl_toolkits.mplot3d

from matplotlib.pyplot import rc  
rc('text', usetex = True)  
rc('font', size=9, family='serif', serif='Times')

fig = pyplot.figure(figsize=(8/2.5, 5/2.5))  
ax = fig.gca(projection='3d')

plot = ax.plot([.1,.2,.3],[.1,.2,.3])

xLabel = ax.set_xlabel('XxxXxxX')  
yLabel = ax.set_ylabel('YyyYyyY')  
zLabel = ax.set_zlabel('ZzzZzzZ')  # \n in here produces an error or is ignored see below   

pyplot.show()   

... Things I have tried:
ax.set_ylabel(r"\phantom{x}" "\n" r'ABC', linespacing=-0.5)

Community
  • 1
  • 1
HoWil
  • 413
  • 4
  • 11
  • 2
    what is the question? – Francesco Montesano Mar 25 '13 at 12:51
  • Now it should be clear... maybe you can upload the result plot of the script, you have enough reputation. THX for the comment. – HoWil Mar 25 '13 at 19:00
  • I would suggest you to use `fig.add_subplot` or `fig.add_axes` instead of `fig.gca` – Francesco Montesano Mar 26 '13 at 11:31
  • Thats how it is done in the examples... (e.g. http://matplotlib.org/examples/mplot3d/surface3d_demo.html). I see no advantage when I use `fig.add_axes` (I tested it). – HoWil Mar 27 '13 at 19:36
  • Does this answer your question? [Adjust label positioning in Axes3D of matplotlib](https://stackoverflow.com/questions/5525782/adjust-label-positioning-in-axes3d-of-matplotlib) – Hagbard Oct 12 '20 at 11:21

1 Answers1

2

I found a solution by scrolling down there: Adjust label positioning in Axes3D of matplotlib

Just add:

ax.xaxis._axinfo['label']['space_factor'] = 2.0
ax.yaxis._axinfo['label']['space_factor'] = 2.0
ax.zaxis._axinfo['label']['space_factor'] = 2.0

That's the only solution that worked for me.

Community
  • 1
  • 1
  • This didn't work for me but using "axes.yaxis.labelpad=30" as suggested in another answer mentioned in your link did the trick for me. – Hagbard Oct 12 '20 at 11:24