Reference: Graphs and Charts

Axes, grids, curves, charts, networks.

Axes and grids

See Graphs for a guide.

  • Axes(x_range=None, y_range=None, x_length=None, y_length=None, axis_config=None, x_axis_config=None, y_axis_config=None, tips=True): An x and a y axis with ticks; 12 by 6 units unless you give x_length and y_length.
    • .x_axis: The x axis on its own.
    • .y_axis: The y axis on its own.
    • .get_axes(): Both axes, as a group.
    • .coords_to_point(*coords) (also .c2p): The place in the picture of the graph point (x, y).
    • .plot(function, x_range=None, color=None) (also .get_graph): A curve of a Python function f(x) across the x range (or x_range).
    • .plot_parametric_curve(function, t_range=(0, 1), color=YELLOW): A curve from a function of t that returns a point.
    • .input_to_graph_point(x, graph) (also .i2gp): The point on a curve above x.
    • .get_graph_label(graph, label="f(x)", x_val=None, direction=RIGHT, buff=MED_SMALL_BUFF, color=None, dot=False, dot_config=None): A label beside a curve, at x_val.
    • .get_x_axis_label(label, edge=UR, direction=UR, buff=SMALL_BUFF): A label at the end of the x axis.
    • .get_y_axis_label(label, edge=UR, direction=UR, buff=SMALL_BUFF): A label at the top of the y axis.
    • .get_axis_labels(x_label="x", y_label="y"): Labels for both axes.
    • .add_coordinates(*axes_numbers, num_decimal_places=None): Writes the numbers along both axes.
    • .get_area(graph, x_range=None, color=(BLUE, GREEN), opacity=0.3, bounded_graph=None): The shaded area under a curve (or between two), over x_range.
    • .get_riemann_rectangles(graph, x_range=None, dx=0.1, input_sample_type="left", stroke_width=1, stroke_color=BLACK, fill_opacity=1, color=(BLUE, GREEN), show_signed_area=True, bounded_graph=None, blend=False, width_scale_factor=1.001): Rectangles under a curve, as in a Riemann sum.
    • .get_vertical_line(point, line_config=None, line_func=None): A dashed line from a point down to the x axis.
    • .get_horizontal_line(point, line_config=None, line_func=None): A dashed line from a point across to the y axis.
    • .get_T_label(x_val, graph, label=None, label_color=None, triangle_size=MED_SMALL_BUFF, triangle_color=WHITE, line_func=None, line_color=YELLOW): A triangle marker and label on the x axis under a curve point.
    • .get_secant_slope_group(x, graph, dx=None, dx_line_color=YELLOW, dy_line_color=None, dx_label=None, dy_label=None, include_secant_line=True, secant_line_color=GREEN, secant_line_length=10): The secant between x and x + dx on a curve, with the dx and dy lines.
  • NumberLine(x_range=None, length=None, unit_size=1, include_numbers=False, include_tip=False): A line with ticks; include_numbers=True writes the numbers.
    • .number_to_point(number) (also .n2p): The place in the picture of a number on the line.
  • NumberPlane(x_range=None, y_range=None, x_length=None, y_length=None, background_line_style=None): A grid covering the picture, with axes.
  • ComplexPlane(x_range=None, y_range=None, x_length=None, y_length=None, background_line_style=None): A NumberPlane for complex numbers.
    • .number_to_point(number) (also .n2p): The place of a complex number such as 2 + 1j.
  • PolarPlane(radius_max=None, size=None, radius_step=1, azimuth_step=None, azimuth_units="PI radians", azimuth_compact_fraction=True, azimuth_offset=0, azimuth_direction="CCW", azimuth_label_buff=SMALL_BUFF, azimuth_label_font_size=24, radius_config=None, background_line_style=None, faded_line_style=None, faded_line_ratio=1): A grid of circles and spokes.
    • .polar_to_point(radius, azimuth) (also .pr2pt): The place of a point given by radius and angle.
  • ThreeDAxes(x_range=None, y_range=None, z_range=None, x_length=None, y_length=None, z_length=None): Accepted so 3D scripts run; shown as flat axes.
from pymations import *

ax = Axes(x_range=[0, 5, 1], y_range=[0, 25, 5], x_length=8, y_length=5)
curve = ax.plot(lambda x: x ** 2, color=BLUE)
area = ax.get_area(curve, x_range=[1, 3], color=BLUE, opacity=0.4)
play(Create(ax), Create(curve))
play(FadeIn(area))

Curves without axes

  • ParametricFunction(function, t_range=(0, 1), color=YELLOW): A curve from a function of t that returns a point.
  • FunctionGraph(function, x_range=None, color=YELLOW): A curve of y = f(x) without axes.

Charts

  • BarChart(values, bar_names=None, y_range=None, x_length=None, y_length=None, bar_colors=("#003f5c", "#58508d", "#bc5090", "#ff6361", "#ffa600"), bar_width=0.6, bar_fill_opacity=0.7, bar_stroke_width=3): Axes with a bar for each value.
    • .bars: The bars, as a group.
    • .get_bar_labels(color=None, font_size=24, buff=MED_SMALL_BUFF, label_constructor=None): The values written above the bars.
    • .change_bar_values(values, update_colors=True): Sets new bar heights (with .animate, they grow and shrink).
from pymations import *

chart = BarChart([3, 5, 2, 6], bar_names=["A", "B", "C", "D"], y_range=[0, 8, 2])
play(Create(chart))
play(chart.animate.change_bar_values([5, 2, 6, 3]))

Networks

  • Graph(vertices, edges, labels=False, label_fill_color=BLACK, layout="spring", layout_scale=2, layout_config=None, vertex_type=None, vertex_config=None, vertex_mobjects=None, edge_type=None, partitions=None, root_vertex=None, edge_config=None): A network of dots (vertices) joined by lines (edges).
  • DiGraph(vertices, edges, labels=False, label_fill_color=BLACK, layout="spring", layout_scale=2, layout_config=None, vertex_type=None, vertex_config=None, vertex_mobjects=None, edge_type=None, partitions=None, root_vertex=None, edge_config=None): A network whose edges are arrows.
  • GenericGraph(vertices, edges, labels=False, label_fill_color=BLACK, layout="spring", layout_scale=2, layout_config=None, vertex_type=None, vertex_config=None, vertex_mobjects=None, edge_type=None, partitions=None, root_vertex=None, edge_config=None): The shared base of Graph and DiGraph; use those.
    • .change_layout(layout="spring", layout_scale=2, layout_config=None, root_vertex=None): Lays the network out another way ("circular", "spring", "tree"…).
from pymations import *

g = Graph([1, 2, 3, 4], [(1, 2), (2, 3), (3, 4), (4, 1)], layout="circular", labels=True)
play(Create(g))