5

I'm trying to plot 3d bars using bar3d and Axes3D of matplotlib and limiting the z-axis range to [0,1], but .set_zlim3d(0,1) method is not properly working and there is extra offset relative to bounding ticks. These extra offsets are shown by two-headed purple arrows:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax  = Axes3D(fig, azim=65, elev=30)
ax.set_zlim3d(0,1)

Result: enter image description here

My Question:

How to remove the extra offsets from bounding ticks, i.e. 0.0 and 1.0?

(one may say try: ax.set_zlim3d(0.0000001, 0.9999999) which yields in loosing 0.0 and 1.0 ticks)

Mehdi
  • 1,192
  • 1
  • 9
  • 21
  • After `ax.set_zlim3d(0.0000001,1)`, have you tried specifying ticks manually? – Captain Trojan Jun 13 '21 at 13:42
  • @CaptainTrojan Tnx, yes I knew I could solve the problem by doing these kind of tricks (for example setting the tick of `0.0000001` to `'0.0'`). I was interested if there exists an easier and a more general way of doing this. – Mehdi Jun 13 '21 at 14:05
  • 1
    A more general way you say? I believe that would be finding a library that is built to be pixel-perfect. Or do you believe matplotlib contains a function `make_everything_pixel_perfect()`? In that case, it is very safe to assume that would be the default behavior, which it is not. – Captain Trojan Jun 13 '21 at 15:08
  • 1
    In a 2d plot this solution is to set the margin to 0. In a 3d plot, there is x, y , and z margin `ax.set(xmargin=0, ymargin=0, zmargin=0)`, but it doesn't seem to allow for completely removing the margin. Maybe this [Removing axes margins in 3D plot](https://stackoverflow.com/q/16488182/7758804) – Trenton McKinney Jun 13 '21 at 17:42
  • @TrentonMcKinney Tnx, this solved the extra (negative) offset from `0.0`, but positive offset from `1.0` still is there. – Mehdi Jun 14 '21 at 06:38
  • 1
    Here is (I think) the [related issue](https://github.com/matplotlib/matplotlib/issues/18052) on matplotlib's github, perhaps you'd like to also contribute to the discussion there? – Asmus Jun 24 '21 at 07:31

0 Answers0