Repository: ManimCommunity/manim

Issue:
Plots not including origin are not aligned in v0.12.0, but were in v0.11.0
## Description of bug / unexpected behavior
<!-- Add a clear and concise description of the problem you encountered. -->
When plotting a `Surface` on `ThreeDAxes` if the origin is not included in the plot, then the axes and plot are not properly aligned.  This was a previous issue, that was fixed and has returned.

## Expected behavior
<!-- Add a clear and concise description of what you expected to happen. -->
The axes and plot should be aligned even if the origin is not included.

## How to reproduce the issue
<!-- Provide a piece of code illustrating the undesired behavior. -->

<details><summary>Code for reproducing the problem</summary>

```py
from manim import *
import numpy as np

class ThreeDSurfacePlot(ThreeDScene):
    def construct(self):
        resolution_fa = 42
        self.set_camera_orientation(phi=75 * DEGREES, theta=10 * DEGREES)

        axes = ThreeDAxes(
                x_range=(3, 9, 1),
                y_range=(3, 9, 1),
                z_range=(-1, 1, 0.5)
                )

        def param_surface(u, v):
            x = u
            y = v
            z = np.sin(x) * np.cos(y)
            return z

        surface_plane = Surface(
            func=lambda u, v: axes.c2p(u, v, param_surface(u, v)),
            resolution=(resolution_fa, resolution_fa),
            u_range=[3, 9],
            v_range=[3, 9]
        )

        self.add(axes, surface_plane)

        self.begin_ambient_camera_rotation(rate=-0.3)
        self.wait(10)
```

</details>


## Additional media files
<!-- Paste in the files manim produced on rendering the code above. -->

<details><summary>Images/GIFs</summary>

https://user-images.githubusercontent.com/79891353/140657483-79245e7a-69cc-49f9-b3c0-5c102f8f02a5.mp4

</details>


## System specifications

<details><summary>System Details</summary>

- OS: Ubuntu 21.10
- RAM: 32GB
- Python version (`python/py/python3 --version`): 3.9.7
- Installed modules (provide output from `pip list`):
```
Package                 Version
----------------------- ---------------------
manim                   0.12.0
moderngl                5.6.4
moderngl-window         2.4.0
```
</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`:

```
ffmpeg version 4.4-6ubuntu5 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-7ubuntu1)
configuration: --prefix=/usr --extra-version=6ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100
```
</details>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->
A test should be added as part of any fix, to ensure this doesn't happen again.


Discussion:

Resolving patch:
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py
--- a/manim/mobject/coordinate_systems.py
+++ b/manim/mobject/coordinate_systems.py
@@ -2183,11 +2183,16 @@ def __init__(
 
         z_axis = self._create_axis(self.z_range, self.z_axis_config, self.z_length)
 
-        z_axis.rotate_about_zero(-PI / 2, UP)
-        z_axis.rotate_about_zero(angle_of_vector(self.z_normal))
+        # [ax.x_min, ax.x_max] used to account for LogBase() scaling
+        # where ax.x_range[0] != ax.x_min
+        z_origin = self._origin_shift([z_axis.x_min, z_axis.x_max])
+
+        z_axis.rotate_about_number(z_origin, -PI / 2, UP)
+        z_axis.rotate_about_number(z_origin, angle_of_vector(self.z_normal))
+        z_axis.shift(-z_axis.number_to_point(z_origin))
         z_axis.shift(
             self.x_axis.number_to_point(
-                self._origin_shift([z_axis.x_min, z_axis.x_max]),
+                self._origin_shift([self.x_axis.x_min, self.x_axis.x_max]),
             ),
         )
 


Test patch:
diff --git a/tests/test_axes_shift.py b/tests/test_axes_shift.py
--- a/tests/test_axes_shift.py
+++ b/tests/test_axes_shift.py
@@ -1,10 +1,56 @@
 import numpy as np
 import pytest
 
-from manim.mobject.coordinate_systems import Axes
+from manim.mobject.coordinate_systems import Axes, ThreeDAxes
+from manim.utils.scale import LogBase
 
 
 def test_axes_origin_shift():
     ax = Axes(x_range=(5, 10, 1), y_range=(40, 45, 0.5))
     assert np.allclose(ax.coords_to_point(5, 40), ax.x_axis.number_to_point(5))
     assert np.allclose(ax.coords_to_point(5, 40), ax.y_axis.number_to_point(40))
+
+
+def test_axes_origin_shift_logbase():
+    ax = Axes(
+        x_range=(5, 10, 1),
+        y_range=(3, 8, 1),
+        x_axis_config={"scaling": LogBase()},
+        y_axis_config={"scaling": LogBase()},
+    )
+    assert np.allclose(
+        ax.coords_to_point(10 ** 5, 10 ** 3), ax.x_axis.number_to_point(10 ** 5)
+    )
+    assert np.allclose(
+        ax.coords_to_point(10 ** 5, 10 ** 3), ax.y_axis.number_to_point(10 ** 3)
+    )
+
+
+def test_3daxes_origin_shift():
+    ax = ThreeDAxes(x_range=(3, 9, 1), y_range=(6, 12, 1), z_range=(-1, 1, 0.5))
+    assert np.allclose(ax.coords_to_point(3, 6, 0), ax.x_axis.number_to_point(3))
+    assert np.allclose(ax.coords_to_point(3, 6, 0), ax.y_axis.number_to_point(6))
+    assert np.allclose(ax.coords_to_point(3, 6, 0), ax.z_axis.number_to_point(0))
+
+
+def test_3daxes_origin_shift_logbase():
+    ax = ThreeDAxes(
+        x_range=(3, 9, 1),
+        y_range=(6, 12, 1),
+        z_range=(2, 5, 1),
+        x_axis_config={"scaling": LogBase()},
+        y_axis_config={"scaling": LogBase()},
+        z_axis_config={"scaling": LogBase()},
+    )
+    assert np.allclose(
+        ax.coords_to_point(10 ** 3, 10 ** 6, 10 ** 2),
+        ax.x_axis.number_to_point(10 ** 3),
+    )
+    assert np.allclose(
+        ax.coords_to_point(10 ** 3, 10 ** 6, 10 ** 2),
+        ax.y_axis.number_to_point(10 ** 6),
+    )
+    assert np.allclose(
+        ax.coords_to_point(10 ** 3, 10 ** 6, 10 ** 2),
+        ax.z_axis.number_to_point(10 ** 2),
+    )