Repository: ManimCommunity/manim

Issue:
The bars are higher than the values provided to the `change_bar_values` method of `BarChart` class
## Description of bug / unexpected behavior
`change_bar_values` method of `BarChart` doesn't work as expected. The bars are higher than the values provided to the method.


## Expected behavior
The bar heights should be of the same heights as provided in the argument.


## How to reproduce the issue

<details><summary>Code for reproducing the problem</summary>

Instantiation of `BarChart` class works as expected.

```python

from manim import *


class BarChartExample(Scene):
    def construct(self):
        bar = BarChart(values=[0.25, 0.5])
        self.add(bar)

```

Output:

![image](https://user-images.githubusercontent.com/26636177/126376445-7abe3b73-d656-4b71-b85d-4be1064bef00.png)


However, while using `change_bar_values` method:

```python

from manim import *


class BarChartExample(Scene):
    def construct(self):
        bar = BarChart(values=[0.25, 0.5])
        bar.change_bar_values([0.50, 0.75])  # new line
        self.add(bar)

```

generates the following output:

![image](https://user-images.githubusercontent.com/26636177/126376724-b42d6860-77a5-4913-b8ff-f49cf056dab1.png)


</details>


## Additional media files
<!-- Paste in the files manim produced on rendering the code above. -->

<details><summary>Images/GIFs</summary>

<!-- PASTE MEDIA HERE -->

</details>


## Logs
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->

```
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR
```

<!-- Insert screenshots here (only when absolutely necessary, we prefer copy/pasted output!) -->

</details>


## System specifications

<details><summary>System Details</summary>

- OS: Ubuntu 20.04.2 LTS (running as WSL2 in Windows 11, Version 21H2, OS Build 22000.71):
- RAM: 16 GB
- Python version: Python 3.8.10
- Installed modules (provide output from `pip list`):
```
appdirs             1.4.4
black               21.6b0
certifi             2021.5.30
charset-normalizer  2.0.2
click               7.1.2
click-default-group 1.2.2
cloup               0.7.1
colorama            0.4.4
colour              0.1.5
commonmark          0.9.1
decorator           5.0.9
glcontext           2.3.4
idna                3.2
manim               0.8.0
ManimPango          0.3.0
mapbox-earcut       0.12.10
moderngl            5.6.4
moderngl-window     2.4.0
multipledispatch    0.6.0
mypy-extensions     0.4.3
networkx            2.5.1
numpy               1.21.0
pathspec            0.8.1
Pillow              8.2.0
pip                 21.1.3
pkg-resources       0.0.0
pycairo             1.20.1
pydub               0.25.1
pyglet              1.5.18
Pygments            2.9.0
pyrr                0.10.3
regex               2021.7.6
requests            2.26.0
rich                10.6.0
scipy               1.7.0
screeninfo          0.6.7
setuptools          44.0.0
six                 1.16.0
toml                0.10.2
tqdm                4.61.2
urllib3             1.26.6
watchdog            2.1.3
xdg-open-wsl        1.0.0
```
</details>

<details><summary>LaTeX details</summary>

+ LaTeX distribution (e.g. TeX Live 2020):
+ Installed LaTeX packages:

(Sorry cannot open the GUI on WSL)

```
pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian)
kpathsea version 6.3.1
Copyright 2019 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.01
```
</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`:

```
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
```
</details>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->



Discussion:

Resolving patch:
diff --git a/manim/mobject/probability.py b/manim/mobject/probability.py
--- a/manim/mobject/probability.py
+++ b/manim/mobject/probability.py
@@ -267,19 +267,21 @@ def __init__(
         self.bar_stroke_width = bar_stroke_width
         self.bar_names = bar_names
         self.bar_label_scale_val = bar_label_scale_val
+        self.total_bar_width = width
+        self.total_bar_height = height
 
         if self.max_value is None:
             self.max_value = max(values)
 
-        self.add_axes(width, height)
-        self.add_bars(values, width, height)
+        self.add_axes()
+        self.add_bars(values)
         self.center()
 
-    def add_axes(self, width, height):
-        x_axis = Line(self.tick_width * LEFT / 2, width * RIGHT)
-        y_axis = Line(MED_LARGE_BUFF * DOWN, height * UP)
+    def add_axes(self):
+        x_axis = Line(self.tick_width * LEFT / 2, self.total_bar_width * RIGHT)
+        y_axis = Line(MED_LARGE_BUFF * DOWN, self.total_bar_height * UP)
         ticks = VGroup()
-        heights = np.linspace(0, height, self.n_ticks + 1)
+        heights = np.linspace(0, self.total_bar_height, self.n_ticks + 1)
         values = np.linspace(0, self.max_value, self.n_ticks + 1)
         for y, _value in zip(heights, values):
             tick = Line(LEFT, RIGHT)
@@ -301,12 +303,12 @@ def add_axes(self, width, height):
             self.y_axis_labels = labels
             self.add(labels)
 
-    def add_bars(self, values, width, height):
-        buff = float(width) / (2 * len(values) + 1)
+    def add_bars(self, values):
+        buff = float(self.total_bar_width) / (2 * len(values) + 1)
         bars = VGroup()
         for i, value in enumerate(values):
             bar = Rectangle(
-                height=(value / self.max_value) * height,
+                height=(value / self.max_value) * self.total_bar_height,
                 width=buff,
                 stroke_width=self.bar_stroke_width,
                 fill_opacity=self.bar_fill_opacity,
@@ -329,5 +331,5 @@ def add_bars(self, values, width, height):
     def change_bar_values(self, values):
         for bar, value in zip(self.bars, values):
             bar_bottom = bar.get_bottom()
-            bar.stretch_to_fit_height((value / self.max_value) * self.height)
+            bar.stretch_to_fit_height((value / self.max_value) * self.total_bar_height)
             bar.move_to(bar_bottom, DOWN)


Test patch: