manim icon indicating copy to clipboard operation
manim copied to clipboard

`Axes` and its submobjects does not respect passed colors

Open Ironman1905 opened this issue 1 year ago • 5 comments

Description of bug / unexpected behavior

I set the background is white, but the numbers with Black color nearby the axis don't display

Expected behavior

I should see the black number label when background is white

How to reproduce the issue

Code for reproducing the problem
from manim import *
#from scipy.stats import norm
#import os
config.media_width="10%"
config.background_color="WHITE"
class Test(Scene):
    def construct(self):
       
       
        axes = Axes( x_range=[-1,8],y_range=[-1,70], 
                    #axis_config={"color": BLACK},
                    x_axis_config={"color": BLACK,
                                    "include_numbers": True,
                                   "decimal_number_config": {
                                    "color": BLACK,
                                   "num_decimal_places": 0 
                                     }
                                   }, 
                    y_axis_config={"color": BLACK,
                                   "include_ticks": False}
        )
        self.add(axes)
        redcolor=ManimColor.from_rgb([255,0,0])
        bluecolor=ManimColor.from_rgb([0,0,255])
        Parabola_graph=axes.plot(lambda x: x**3, color=bluecolor)
        line_graph=axes.plot(lambda x: 15*x+4, color=redcolor)
        self.play(Create(Parabola_graph), Create(line_graph),run_time=5)

Additional media files

Images/GIFs

Logs

Terminal output
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)):
  • RAM:
  • Python version (python/py/python3 --version):
  • Installed modules (provide output from pip list):
PASTE HERE
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
  • Installed LaTeX packages:
FFMPEG

Output of ffmpeg -version:

PASTE HERE

Additional comments

Ironman1905 avatar Feb 29 '24 10:02 Ironman1905

This is an issue with how coloring of Axes is handled during initialization of the object. The best solution (for now) is to take care of coloring in a second step, after creating the object:

from manim import *

config.background_color = WHITE

class Test(Scene):
    def construct(self):
        axes = Axes(x_range=[-1, 8], y_range=[-1, 70], 
            x_axis_config={
                "include_numbers": True,
                "decimal_number_config": {"num_decimal_places": 0}
            }, 
            y_axis_config={"include_ticks": False}
        )
        axes.set_color(BLACK)
        self.add(axes)
        redcolor = ManimColor.from_rgb([255,0,0])
        bluecolor = ManimColor.from_rgb([0,0,255])
        Parabola_graph = axes.plot(lambda x: x**3, color=bluecolor)
        line_graph = axes.plot(lambda x: 15*x+4, color=redcolor)
        self.play(Create(Parabola_graph), Create(line_graph), run_time=5)

behackl avatar Apr 20 '24 09:04 behackl

+1 When animating the axis with e.g. self.play(Write(axes)), the numbers briefly show up

jherkenhoff avatar May 22 '24 16:05 jherkenhoff

Is this issue resolved? I tried the same code as

Code for reproducing the problem

from manim import *
#from scipy.stats import norm
#import os
config.media_width="10%"
config.background_color="WHITE"
class Test(Scene):
    def construct(self):
       
       
        axes = Axes( x_range=[-1,8],y_range=[-1,70], 
                    #axis_config={"color": BLACK},
                    x_axis_config={"color": BLACK,
                                    "include_numbers": True,
                                   "decimal_number_config": {
                                    "color": BLACK,
                                   "num_decimal_places": 0 
                                     }
                                   }, 
                    y_axis_config={"color": BLACK,
                                   "include_ticks": False}
        )
        self.add(axes)
        redcolor=ManimColor.from_rgb([255,0,0])
        bluecolor=ManimColor.from_rgb([0,0,255])
        Parabola_graph=axes.plot(lambda x: x**3, color=bluecolor)
        line_graph=axes.plot(lambda x: 15*x+4, color=redcolor)
        self.play(Create(Parabola_graph), Create(line_graph),run_time=5)

And got this output image

mdhvg avatar Oct 17 '24 10:10 mdhvg

I have boiled down the issue to the DecimalNumber class used inside the Axes class.

We can see in the following code, when the color is BLACK, we get a white number.

I have made the background grey, so that we can see both the colors as and when they appear.

This unexpected behavior is only for the BLACK color. Any other color works just fine.

from manim import *

config.media_width = "10%"
config.background_color = "GREY"
config.quality = "low_quality"


class Test(Scene):
    def construct(self):
        deciBlack = DecimalNumber(5, color=BLACK)
        deciGreen = DecimalNumber(5, color=GREEN)

        deciGreen.next_to(deciBlack, direction=DOWN)
        self.play(Write(deciBlack), Write(deciGreen))
        self.wait(1)

ishu9bansal avatar Jun 12 '25 08:06 ishu9bansal

Added a fix for this issue in this PR. @behackl We might need to rethink about some of the underlying assumptions of the VMobject class initializing the color properties.

However for mitigating this specific issue I've opened this PR. It is a very small change (1 line) and safe change. Please review. #4291

I've explained the mitigation steps in detail inside the PR description.

ishu9bansal avatar Jun 20 '25 08:06 ishu9bansal