본문 바로가기

Programming/Manim Lectures

[05-5-D] Grid Background: NumberPlane

반응형

In this page, we will learn about NumberPlane, which has x and y axes and displays the coordinate system on the screen in a grid. Using NumberPlane makes graph creation and display easy.

 

NumberPlane class

object > Container > Mobject > VMobject > > VGroup > Axes > NumberPlane
manimlib.mobject.coordinate_system.NumberPlane(self, **kwargs)

Axes are used to create a coordinate system, and a grid is displayed on the screen, making it easy to know the location.

 

    CONFIG = {
        "axis_config": {
            "stroke_color": WHITE,
            "stroke_width": 2,
            "include_ticks": False,
            "include_tip": False,
            "line_to_number_buff": SMALL_BUFF,
            "label_direction": DR,
            "number_scale_val": 0.5,
        },
        "y_axis_config": {
            "label_direction": DR,
        },
        "background_line_style": {
            "stroke_color": BLUE_D,
            "stroke_width": 2,
            "stroke_opacity": 1,
        },
        # Defaults to a faded version of line_config
        "faded_line_style": None,
        "x_line_frequency": 1,
        "y_line_frequency": 1,
        "faded_line_ratio": 1,
        "make_smooth_after_applying_functions": True,
    }
Parameters: **kwargs
    CONFIG values of NumberPlane, Coordinate and VMobject/Mobject

    Frequently used variables are, 
    - axis_config: Common variables for x-axis and y-axis    
      - stroke_color=WHITE: Line color
      
      - stroke_width=2: Line thickness
      
      - include_ticks=False: Whether display tick or not
      
      - include_tip=False: Whether include tip(arrow) or not
      
      - line_to_number_buff=SMALL_BUFF=0.1: Size of space between axis line and number
      
      - label_direction=DR: The direction of the axis label elative to the axis line.
      
      - number_scale_val=0.5: Scale ratio of DecimalNumber representing the axis value.
      
      
    - y_axis_config: Properties for y_axis
      - label_direction=DR: Position of y-axis label. 
                    Default is DR. 
                    The y-axis is a 90-degree rotation of the NumberLine. 
                    If rotated in the DR state, 
                    the final label position is on the right side of the y-axis line. 
                    
      - Other NumberLine property values
      
    - background_line_style: Properties of grid lines displayed on the background 
      - stroke_color=BLUE_D: Grid line color
      
      - stroke_width=2: Grid line thickness
      
      - stroke_opacity=1: Grid line opacity
      
      - Other Line property values

Let's create NumberPlane by default. The screen will fill with a checkered grid.

 

plane = NumberPlane()
self.add(plane)
self.wait()

 

Capture image of the video


By default, NumberPlane's Axes use the maximum value of the screen frame on the x-axis and y-axis, and the scale is 1. That is, the position value of the screen and the value of the coordinate system are the same.

 

Let's check this by creating a NumberPlane and displaying the values of the Axes that NumberPlane has.

 

        plane = NumberPlane()

        axes = plane.get_axes()
        x_axis = axes[0]
        y_axis = axes[1]

        print("x_axis:")
        print("  x_min:", x_axis.x_min)
        print("  x_max:", x_axis.x_max)
        print("  unit_size:", x_axis.unit_size)

        print("y_axis:")
        print("  y_min:", y_axis.x_min)
        print("  y_max:", y_axis.x_max)
        print("  unit_size:", y_axis.unit_size)

By doing the above, you can get the basic property values of the axis.

 

Note that y_axis.x_min and y_axis.x_max are used when calculating the minimum and maximum values for y_axis.

This is because the axis was created with the NumberLine class, and in this NumberLine class there are only x_min and x_max property.

The y-axis is used by rotating the NumberLien by 90 degrees.

 

When you run the program, the following is displayed on the console screen.

 

x_axis:
  x_min: -7.111111111111111
  x_max: 7.111111111111111
  unit_size: 1
y_axis:
  y_min: -4.0
  y_max: 4.0
  unit_size: 1

Let's create a sine graph on top of the default NumberPlane.

 

    def sine_graph(self):
        plane = NumberPlane()
        graph = plane.get_graph(
            lambda x: np.sin(x),
            color=YELLOW
        )

        self.add(plane, graph)
        self.wait()

 

Captured image of the video


Next: [05-5-E] Scene for Graph: GraphScene

 

[05-5-E] Scene for Graph: GraphScene

GraphScene is a scene specialized for graphs. You can create your own coordinate system by specifying the x-axis and y-axis properties with the CONFIG value, and get a graph by the get_graph method...

infograph.tistory.com

Go To: [99] Table of Contents

반응형

'Programming > Manim Lectures' 카테고리의 다른 글

[06] Animation  (0) 2020.06.09
[05-5-E] Scene for Graph: GraphScene  (0) 2020.06.07
[05-5-C] Graph Coordinate: Axes  (0) 2020.06.07
[05-5-B] Graph Line: NumberLine  (0) 2020.06.07
[05-5-A] Graph from ParametricFunction/FunctionGraph  (0) 2020.06.07