- 我正在尝试创建一个 GraphScene 并绘制一个介于 0 和 1 之间的函数。
- 我想要 0.1 和 0.3 的标签。
- 我试图通过传递
"x_labeled_nums": np.array([0.1, 0.3, 1])
然后"x_axis": {"decimal_number_config": {"num_decimal_places": 2}}
在中来实现这一点,CONFIG
但我仍然在 x 轴上显示整数,我试图让它渲染浮点数 0.1 和 0.3
class PlotFloats(GraphScene):
CONFIG = {
"x_min": 0,
"x_max": 1,
"x_axis_label": "X",
"y_min": 0,
"y_max": 2,
"y_axis_label": "Y",
"x_axis": {
"decimal_number_config": {"num_decimal_places": 2}
},
"function_color": RED,
"x_labeled_nums": np.array([0.1, 0.3, 1]),
}
def construct(self):
self.setup_axes(animate=True)
func_graph = self.get_graph(self.func_to_graph, self.function_color)
self.play(ShowCreation(func_graph))
def func_to_graph(self, x):
return max(0.05, min(1, (0.95 / 0.2) * (x - 0.1)))
链接到输出