Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Comments

Fix x_range slicing in get_area_under_graph to prevent TypeError#2395

Merged
3b1b merged 1 commit into3b1b:masterfrom
mathsvisualization:bugfix/xrange-typeerror
Feb 10, 2026
Merged

Fix x_range slicing in get_area_under_graph to prevent TypeError#2395
3b1b merged 1 commit into3b1b:masterfrom
mathsvisualization:bugfix/xrange-typeerror

Conversation

@mathsvisualization
Copy link
Contributor

Motivation

Fix a bug in get_area_under_graph where passing the full graph.x_range
to inverse_interpolate could cause a TypeError:

TypeError: inverse_interpolate() takes 3 positional arguments but 4 were given

This happened when graph.x_range had more than 2 elements. Slicing the
x_range ensures that alpha bounds are calculated correctly and subgraphs
are created reliably.

Proposed changes

  • Slice graph.x_range to only the first two elements when passing to inverse_interpolate: graph.x_range[:2].
  • Preserve existing behavior for standard 2-element x_range.

Test

Code:

from manimlib import *

class HelloWorldExample(InteractiveScene):
    def construct(self):
        # Setup
        plane = NumberPlane(
            x_range=(-4, 4), y_range=(0, 1.5, 0.5),
            width=14, height=5,
            background_line_style=dict(
                stroke_color=GREY_B,
                stroke_width=2,
                stroke_opacity=0.75
            )
        )
        plane.to_edge(DOWN)
        plane.x_axis.add_numbers(num_decimal_places=1, excluding=[0])
        plane.y_axis.add_numbers(font_size=24)
        self.add(plane)

        # graph
        graph = plane.get_graph(lambda x: np.exp(-x**2))
        graph.set_stroke(BLUE, 2)
        self.add(graph)

        area = plane.get_area_under_graph(graph, x_range=[-1, 1])
        area.scale(0.7)
        area.next_to(graph.pfp(0.65), UR)
        self.add(area)

Result:

  • No TypeError occurs
  • Area under the graph is filled correctly for both standard and extended x_ranges

Before:

Screenshot (55)

After:

Screenshot (56)

@3b1b 3b1b merged commit 14f5f8e into 3b1b:master Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants