我需要绘制一个水平轴来描述数字,目前有一个 NumberLine 可以工作,但是没有箭头指示正方向。
是否有内置对象可以做到这一点?或者用代码手动创建这样的类?
如果您对对象的工作方式有疑问,可以在源代码中查找它。manimlib/mobject/
在您的情况下,它在 number_line.py 中,代码不难理解,因此您避免询问。
class NumberLineExample(Scene):
def construct(self):
nl=NumberLine(x_min=-2,
x_max=2,
include_numbers=True,
include_tip=True,
label_direction=UP
)
self.add(nl)
如果您看到源代码,您会发现所有选项:
class NumberLine(Line):
CONFIG = {
"color": LIGHT_GREY,
"x_min": -FRAME_X_RADIUS,
"x_max": FRAME_X_RADIUS,
"unit_size": 1,
"include_ticks": True,
"tick_size": 0.1,
"tick_frequency": 1,
# Defaults to value near x_min s.t. 0 is a tick
# TODO, rename this
"leftmost_tick": None,
# Change name
"numbers_with_elongated_ticks": [0],
"include_numbers": False,
"numbers_to_show": None,
"longer_tick_multiple": 2,
"number_at_center": 0,
"number_scale_val": 0.75,
"label_direction": DOWN,
"line_to_number_buff": MED_SMALL_BUFF,
"include_tip": False,
"tip_width": 0.25,
"tip_height": 0.25,
"decimal_number_config": {
"num_decimal_places": 0,
},
"exclude_zero_from_default_numbers": False,
}