ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
26.46k stars 1.81k forks source link

`unit_size` does not work in Axes #2336

Open Elteoremadebeethoven opened 2 years ago

Elteoremadebeethoven commented 2 years ago

Description of bug / unexpected behavior

The Axes class does not respect the "unit_size" setting with the x_axis_config or y_axis_config parameter.

Expected behavior

If you change Axes to NumberPlane then it solves:

class Test1(Scene):
    def construct(self):
        axes = NumberPlane(
            x_range=[-3,3,1],
            y_range=[-6,6,2],
            x_axis_config={
                "unit_size": 1
            },
            y_axis_config={
                "unit_size": 0.5
            }
        )
        self.add(axes)

image

How to reproduce the issue

class AxesBug(Scene):
    def construct(self):
        axes = Axes(
            x_range=[-3,3,1],
            y_range=[-6,6,2],
            x_axis_config={
                "unit_size": 1
            },
            y_axis_config={
                "unit_size": 0.5
            }
        )
        self.add(axes)

image

My specs.

Manim 0.12, tested on MacOS M1 Big Sur and Linux Mint 20.1

hydrobeam commented 2 years ago

The reason this happens is that length overwrites unit_size, and length is specified by default for an Axes. NumberPlane lets the parameter be None, so specifying a unit_size works. See NumberLine docs for the parameter description.

It's a little janky, but a way you can get around this is by explicitly stating x_length=None and y_length=None for an Axes.

Elteoremadebeethoven commented 2 years ago

Ok, is that the expected behavior? If so then I can close the issue

behackl commented 2 years ago

This can be resolved together with #2479 by making None the default value for x_length and y_length and then checking whether either these two or unit_size is set.