Search code examples
pythonplotaxismanim

How to change the color of axis labels in ManimCommunity/manim's ComplexPlane?


I would like to have a "light theme" for my plots to be "PDF-friendly" in manim v.0.18.0. Thus, the background should be white and the plot itself with the labels should be black. I am able to achieve most of this using the following code.

from manim import *

class WhiteThemeExample(Scene):
    def construct(self):
        self.camera.background_color = WHITE
        point = -3 + 4j
        plane = ComplexPlane(x_range=(-4, 4, 1), y_range=(-1, 5, 1), axis_config={"color": BLACK})
        self.add(plane)
        dot = Dot(plane.n2p(point), color=ORANGE)
        label = MathTex("-3+4i", color=BLACK).next_to(dot, UR, 0.1)
        self.add(dot, label)
        plane.add_coordinates()
        origin = Dot(plane.n2p(0 + 0j), color=BLACK)
        line = Line(origin, dot, color=BLACK)
        self.add(origin, line)

This is run using

manim render -pqh -s .\plot.py WhiteThemeExample

The result is this: the axis labels are still white.

Manim complex plane plot with white labels:

Manim complex plane plot with white labels

How can I change these labels to be black?

I've tried passing color, fill_color, stroke_color to axis_config, x_axis_config, and decimal_number_config to ComplexPlane's constructor but no luck (or maybe I'm doing it wrong).


Solution

  • Correct answer was provided by @CodingWithMagga :

    class WhiteThemeExample(Scene):
        def construct(self):
            self.camera.background_color = WHITE
            point = -3 + 4j
            plane = ComplexPlane(x_range=(-4, 4, 1), y_range=(-1, 5, 1), axis_config={"color": BLACK})
            self.add(plane)
            dot = Dot(plane.n2p(point), color=ORANGE)
            label = MathTex("-3+4i", color=BLACK).next_to(dot, UR, 0.1)
            self.add(dot, label)
    
            # these two lines are the answer
            labels = plane.get_coordinate_labels().set_color(BLACK)
            self.add(labels)
    
            origin = Dot(plane.n2p(0 + 0j), color=BLACK)
            line = Line(origin, dot, color=BLACK)
            self.add(origin, line)
    

    Resulting figure