def get_graph_label(self, graph, label="f(x)", x=None, direction=RIGHT, buff=MED_SMALL_BUFF, color=None): if isinstance(label, str): label = Tex(label) if color is None: label.match_color(graph) if x is None: # Searching from the right, find a point # whose y value is in bounds max_y = FRAME_Y_RADIUS - label.get_height() max_x = FRAME_X_RADIUS - label.get_width() for x0 in np.arange(*self.x_range)[::-1]: pt = self.i2gp(x0, graph) if abs(pt[0]) < max_x and abs(pt[1]) < max_y: x = x0 break if x is None: x = self.x_range[1] point = self.input_to_graph_point(x, graph) angle = self.angle_of_tangent(x, graph) normal = rotate_vector(RIGHT, angle + 90 * DEGREES) if normal[1] < 0: normal *= -1 label.next_to(point, normal, buff=buff) label.shift_onto_screen() return label
def get_axis_label(self, label_tex, axis, edge, direction, buff=MED_SMALL_BUFF): label = Tex(label_tex) label.next_to( axis.get_edge_center(edge), direction, buff=buff ) label.shift_onto_screen(buff=MED_SMALL_BUFF) return label
def get_axis_label(self, label_tex: str, axis: np.ndarray, edge: np.ndarray, direction: np.ndarray, buff: float = MED_SMALL_BUFF) -> Tex: label = Tex(label_tex) label.next_to(axis.get_edge_center(edge), direction, buff=buff) label.shift_onto_screen(buff=MED_SMALL_BUFF) return label
def get_graph_label( self, graph, label="f(x)", x_val=None, direction=RIGHT, buff=MED_SMALL_BUFF, color=None, ): label = Tex(label) color = color or graph.get_color() label.set_color(color) if x_val is None: # Search from right to left for x in np.linspace(self.x_max, self.x_min, 100): point = self.input_to_graph_point(x, graph) if point[1] < FRAME_Y_RADIUS: break x_val = x label.next_to(self.input_to_graph_point(x_val, graph), direction, buff=buff) label.shift_onto_screen() return label