from manim import *
class ThreeDAxesLabels(ThreeDScene):
    """3.2 自定义三轴颜色、粗细与中文轴标签。
    get_axis_labels() 返回 VGroup，必须自己上屏；
    中文 Text 必须指定 font="STLiti"，否则是豆腐块。
    """
    def construct(self):
        self.set_camera_orientation(phi=65 * DEGREES, theta=-50 * DEGREES)
        title = Text("自定义三轴颜色与标签", font="STLiti", font_size=32).to_edge(UP)
        self.add_fixed_in_frame_mobjects(title)
        axes = ThreeDAxes(
            x_axis_config=dict(color=RED, stroke_width=2),
            y_axis_config=dict(color=GREEN, stroke_width=4),
            z_axis_config=dict(color=BLUE, stroke_width=6),
        ).scale(0.65)
        labels = axes.get_axis_labels(
            Text("人口", font="STLiti", font_size=26, color=RED),
            Text("年龄", font="STLiti", font_size=26, color=GREEN),
            Text("收入", font="STLiti", font_size=26, color=BLUE),
        )
        legend = VGroup(
            Text("x 轴  人口", font="STLiti", font_size=22, color=RED),
            Text("y 轴  年龄", font="STLiti", font_size=22, color=GREEN),
            Text("z 轴  收入", font="STLiti", font_size=22, color=BLUE),
        ).arrange(DOWN, aligned_edge=LEFT, buff=0.16).to_corner(DL)
        self.add_fixed_in_frame_mobjects(legend)
        self.play(FadeIn(title), run_time=0.6)
        self.play(FadeIn(axes), run_time=1.6)
        self.play(LaggedStart(*[FadeIn(x) for x in labels],
                              lag_ratio=0.3, run_time=1.2))
        self.play(FadeIn(legend), run_time=0.8)
        note = Text("3D 中的 Text 会随相机倾斜，重要中文建议做固定朝向图例",
                    font="STLiti", font_size=20, color=YELLOW).to_edge(DOWN)
        self.add_fixed_in_frame_mobjects(note)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(2.6)
