Charts¶
A bar chart is axes with a bar for each value, which grow and shrink as the values change. A sample space is a rectangle that stands for all the outcomes of a chance: divide it into parts whose areas are their probabilities.
BarChart ¶

A bar chart: a bar for each value, rising from the x-axis (or hanging below it, for a negative value), on axes with a numbered y-axis; the bars colored along a gradient.
Each bar stands in its own unit of the x-axis, centered in it and bar_width of it
wide, and it is as tall as its value, in the y-axis's units. The bars' names go
below the x-axis (above it, under a negative bar).
change_bar_values changes the bars, and
get_bar_labels writes their values beside them.
The chart is Axes: its x-axis runs from 0 to the number of bars.
valuesThe values, one bar each, from left to right.
bar_namesThe bars' names, written by the x-axis, typeset as text; None for none.
y_rangeThe y-axis's range,
[y_min, y_max, y_step]; None to fit the values, from 0 (or the lowest value, if negative) to the highest (or 0), with a step of about one scene unit. Given two numbers, the step is that one.x_lengthThe x-axis's length, in scene units; None for one scene unit per bar, at most the frame's width less 2.
y_lengthThe y-axis's length, in scene units; None for 4, the frame's height less 4.
bar_colorsThe bars' colors: a gradient over them, from left to right.
bar_widthEach bar's width, as a fraction of its unit of the x-axis.
bar_fill_opacityThe bars' fill opacity, from 0 to 1.
bar_stroke_widthThe width of the bars' outlines, in hundredths of a scene unit.
It also takes
the Axes keywords.
Source
src/manimgx/mobjects/plotting.py
values ¶
The chart's values, one per bar, as they are now.
bars ¶
The bars, rectangles, from left to right.
get_bar_labels ¶

Make labels of the bars' values: each above its bar (below it, for a negative value), in the bar's color unless given another.
bar_chart.get_bar_labels(color=None, font_size=24, buff=MED_SMALL_BUFF, label_constructor=Tex)
colorThe labels' color; None for each bar's fill color.
font_sizeTheir font size.
buffThe gap between each bar and its label, in scene units.
label_constructor
Returns A new group of the labels, from left to right, not added to the chart.
Source
src/manimgx/mobjects/plotting.py
change_bar_values ¶
Change the bars' values: each bar is stretched to its new height from the x-axis, crossing to its other side if the value changes sign.
The y-axis stays as it is, and labels made before do not follow; to animate the
change, use .animate.
valuesThe new values, from left to right; fewer than the bars change the first ones only.
update_colorsWhether to color the bars along the chart's gradient again (a bar remade from a value of 0 needs it).
Source
src/manimgx/mobjects/plotting.py
SampleSpace ¶

Code
import manimgx as m
class SampleSpaceExample(m.Scene):
def construct(self) -> None:
space = m.SampleSpace(width=6, height=5)
space.divide_vertically(0.4, colors=[m.BLUE_E, m.GREY_BROWN])
rain, dry = space.vertical_parts
colors = [m.RED_E, m.TEAL_E]
rain.add(rain.get_division_along_dimension(0.7, 1, colors, m.DOWN))
dry.add(dry.get_division_along_dimension(0.2, 1, colors, m.DOWN))
rain_label = m.Text("rain").next_to(rain, m.DOWN)
dry_label = m.Text("dry").next_to(dry, m.DOWN)
self.add(space, rain_label, dry_label)
A sample space: a rectangle standing for all the outcomes, to divide into parts whose areas are probabilities; dark grey, filled, with a thin light grey outline, unless styled.
divide_vertically splits it into vertical
strips, one per probability, from left to right, and keeps them as its
vertical_parts;
get_division_along_dimension
makes the parts of a division along either side, in either direction. Each part is
a sample space itself, which can be divided in turn.
heightIts height, in scene units.
widthIts width, in scene units.
default_label_scale_valAccepted for Manim compatibility; ignored.
colorThe color of both fill and stroke (default white); None for the class's default.
fill_colorThe fill's color;
colorif not given. Several colors make a gradient alongsheen_direction.fill_opacityThe fill's opacity, from 0 to 1 (default 0: no fill).
stroke_colorThe stroke's color;
colorif not given. Several colors make a gradient.stroke_opacityThe stroke's opacity, from 0 to 1 (default 1).
stroke_widthThe stroke's width, in hundredths of a scene unit (default 4; 0: no stroke).
background_stroke_colorThe color of an outline drawn behind the fill (default black).
background_stroke_opacityThe outline's opacity, from 0 to 1 (default 1).
background_stroke_widthThe outline's width, in hundredths of a scene unit (default 0: none).
sheen_factorHow much the colors lighten toward
sheen_direction, from -1 to 1 (default 0); a negative factor darkens.sheen_directionThe direction the colors lighten toward (default
UL).joint_typeHow the stroke is joined where its path turns: round, beveled or mitered, as a two-dimensional scene draws it (see LineJointType; default AUTO: mitered).
cap_styleHow the stroke ends, at each end it shows (an open path's, a dash's): round, butt or square, as a two-dimensional scene draws it (see CapStyleType; default AUTO: butt).
shade_in_3dWhether a three-dimensional scene's light shades the mobject.
materialHow its surface reflects the scene's lights in a three-dimensional scene (see Material); None: Manim's shading (default).
nameA name for the mobject; its class's name if not given.
z_indexIts place in the drawing order: a higher index is drawn over a lower one (default 0).
targetThe state
MoveToTargetmoves the mobject to.
It also takes the style keywords.
Source
src/manimgx/mobjects/plotting.py
get_division_along_dimension ¶
Make the parts that divide the sample space along a dimension, one per probability, each that fraction of it.
The parts follow one another in the direction vect, from the space's edge
opposite it; they are colored along a gradient of colors, and each is a sample
space itself.
p_listThe probabilities: a part is added for the rest, if they sum to less than 1.
dimThe dimension divided: 0 for the width, 1 for the height.
colorsThe colors, a gradient over the parts.
vectThe direction the parts follow one another in.
Returns A new group of the parts, not added to the space.
Source
src/manimgx/mobjects/plotting.py
get_vertical_division ¶
Make vertical strips that divide the sample space, one per probability, from left to right (see get_division_along_dimension).
sample_space.get_vertical_division(p_list, colors=(MAROON_B, YELLOW), vect=RIGHT)
p_listThe probabilities, completed to sum to 1.
colorsThe colors, a gradient over the strips.
vectThe direction the strips follow one another in: RIGHT, from the left.
Returns A new group of the strips, not added to the space.
Source
src/manimgx/mobjects/plotting.py
divide_vertically ¶

Code
import manimgx as m
class SampleSpaceDivideVerticallyExample(m.Scene):
def construct(self) -> None:
space = m.SampleSpace(width=9, height=4)
space.divide_vertically([0.25, 0.25], colors=[m.RED_E, m.GOLD_E])
parts = space.vertical_parts
labels = [m.Text(n).move_to(p) for n, p in zip("ABC", parts)]
self.add(space, *labels)
Divide the sample space into vertical strips, one per probability, from left to right: each is that fraction of its width.
The probabilities are completed to sum to 1. The strips are added to the space,
as one group, and kept as its vertical_parts.
sample_space.divide_vertically(p_list, colors=(MAROON_B, YELLOW), vect=RIGHT)
p_listA probability, or probabilities.
colorsThe strips' colors: a gradient over them.
vectThe direction the strips follow one another in: RIGHT, from the left.
Source
src/manimgx/mobjects/plotting.py