Search code examples
bar-chartmanim

Manim Diagonal bar_names


I want to animate a bar chart in manim and it works just fine. However, the bar_names are long and have to be displayed rather small. Is there a way to rotate them so they can be displayed bigger?


    CONFIG = {
        "max_value" : 100,
        "bar_names" : ["Fleisch von Wiederkäuern","Anderes Fleisch, Fisch","Milchprodukte","Früchte", "Snacks, etc.","Gemüse","Pflanzliche Öle","Getreideprodukte", "Pflanzliche Proteine"],
        "bar_label_scale_val" : 0.2,
        "bar_stroke_width" : 0,
        "width" : 10,
        "height" : 6,
        "label_y_axis" : False,

    }
    def construct(self):

        composition = [96.350861, 18.5706488, 14.7071608, 8.25588773, 7.33856028, 4.24083463, 1.65574964, 1.36437485, 1]
        chart = BarChart(values=composition, **self.CONFIG)
        self.play(Write(chart), run_time=2)```

Solution

  • Maybe something like this? (I just made new labels so delete the old ones, or delete their size) (also I modified some of the names because my Latex crashed with some characters)

    CONFIG = {
            "height": 4,
            "width": 10,
            "n_ticks": 4,
            "tick_width": 0.2,
            "label_y_axis": False,
            "y_axis_label_height": 0.25,
            "max_value": 100,
            "bar_colors": [BLUE, YELLOW],
            "bar_fill_opacity": 0.8,
            "bar_stroke_width": 0,
            "bar_names": ["Fleisch von Wiederkuern","Anderes Fleisch, Fisch","Milchprodukte","Frchte", "Snacks, etc.","Gemse","Pflanzliche le","Getreideprodukte", "Pflanzliche Proteine"],
            "bar_label_scale_val": 0
    
    
        }
        def construct(self):
            bar_names=["Fleisch von Wiederkuern","Anderes Fleisch, Fisch","Milchprodukte","Frchte", "Snacks, etc.","Gemse","Pflanzliche le","Getreideprodukte", "Pflanzliche Proteine"]
            Lsize=0.55
            Lseparation=1.1
            Lpositionx=-5.4
            Lpositiony=2
            bar_labels = VGroup()
            for i in range(len(bar_names)):
                label = TexMobject(bar_names[i])
                label.scale(Lsize)
                label.move_to(DOWN*Lpositiony+(i*Lseparation+Lpositionx)*RIGHT)
                label.rotate(np.pi*(1.5/6))
                bar_labels.add(label)
                
            
            composition = [96.350861, 18.5706488, 14.7071608, 8.25588773, 7.33856028, 4.24083463, 1.65574964, 1.36437485, 1]
            chart = BarChart(values=composition, **self.CONFIG)
            chart.shift(UP)
            self.play(Write(chart),Write(bar_labels), run_time=2)