or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

animations.mdcameras.mdcoordinate-systems.mdindex.mdmobjects.mdrendering.mdscenes.mdutilities.md

coordinate-systems.mddocs/

0

# Coordinate Systems

1

2

Mathematical coordinate systems and graphing utilities including 2D/3D axes, number lines, polar coordinates, and function plotting with automatic scaling and labeling. These systems provide the mathematical foundation for plotting functions, displaying data, and creating precise mathematical visualizations.

3

4

## Capabilities

5

6

### Base Coordinate System

7

8

Abstract foundation providing common functionality for all coordinate systems including coordinate mapping, scaling, and mathematical transformations.

9

10

```python { .api }

11

class CoordinateSystem:

12

"""

13

Abstract base class providing core coordinate system functionality.

14

15

Defines the interface for coordinate mapping, scaling, and mathematical

16

transformations that all coordinate systems inherit.

17

"""

18

19

def __init__(

20

x_range: Sequence[float] = None,

21

y_range: Sequence[float] = None,

22

x_length: float = None,

23

y_length: float = None,

24

dimension: int = 2

25

) -> None:

26

"""

27

Parameters:

28

- x_range: [x_min, x_max, x_step] for x-axis

29

- y_range: [y_min, y_max, y_step] for y-axis

30

- x_length: Physical length of x-axis in Manim units

31

- y_length: Physical length of y-axis in Manim units

32

- dimension: Coordinate system dimensionality (2 or 3)

33

"""

34

35

# Coordinate mapping methods

36

def coords_to_point(x: float, y: float, z: float = 0) -> np.ndarray:

37

"""Convert mathematical coordinates to Manim scene point."""

38

39

def point_to_coords(point: np.ndarray) -> tuple[float, float, float]:

40

"""Convert Manim scene point to mathematical coordinates."""

41

42

def c2p(x: float, y: float, z: float = 0) -> np.ndarray:

43

"""Alias for coords_to_point - convert coordinates to point."""

44

45

def p2c(point: np.ndarray) -> tuple[float, float, float]:

46

"""Alias for point_to_coords - convert point to coordinates."""

47

48

def __matmul__(coords: Sequence[float]) -> np.ndarray:

49

"""Matrix multiplication syntax for coordinate conversion: axes @ [x, y]."""

50

51

# Axis access methods

52

def get_x_axis() -> NumberLine:

53

"""Get the x-axis as a NumberLine object."""

54

55

def get_y_axis() -> NumberLine:

56

"""Get the y-axis as a NumberLine object."""

57

58

def get_z_axis() -> NumberLine:

59

"""Get the z-axis as a NumberLine object (3D only)."""

60

61

def get_axes() -> VGroup:

62

"""Get all axes as a VGroup."""

63

64

# Range and length properties

65

def get_x_range() -> Sequence[float]:

66

"""Get x-axis range [min, max, step]."""

67

68

def get_y_range() -> Sequence[float]:

69

"""Get y-axis range [min, max, step]."""

70

71

def get_x_length() -> float:

72

"""Get physical x-axis length."""

73

74

def get_y_length() -> float:

75

"""Get physical y-axis length."""

76

```

77

78

### 2D Axes System

79

80

Standard Cartesian coordinate system with customizable axes, ticks, labels, and grid lines for 2D mathematical plotting.

81

82

```python { .api }

83

class Axes(VGroup, CoordinateSystem):

84

"""

85

2D Cartesian coordinate system with full customization.

86

87

Provides x and y axes with ticks, labels, and grid lines for

88

mathematical function plotting and data visualization.

89

"""

90

91

def __init__(

92

x_range: Sequence[float] = None,

93

y_range: Sequence[float] = None,

94

x_length: float = round(config["frame_width"]) - 2,

95

y_length: float = round(config["frame_height"]) - 2,

96

axis_config: dict = None,

97

x_axis_config: dict = None,

98

y_axis_config: dict = None,

99

tips: bool = True,

100

**kwargs

101

) -> None:

102

"""

103

Parameters:

104

- x_range: [x_min, x_max, x_step] for x-axis domain

105

- y_range: [y_min, y_max, y_step] for y-axis domain

106

- x_length: Physical width of coordinate system

107

- y_length: Physical height of coordinate system

108

- axis_config: Configuration applied to both axes

109

- x_axis_config: Configuration specific to x-axis

110

- y_axis_config: Configuration specific to y-axis

111

- tips: Whether to show arrow tips on axes

112

"""

113

114

# Function plotting methods

115

def plot(

116

function: Callable[[float], float],

117

x_range: Sequence[float] = None,

118

use_vectorized: bool = False,

119

discontinuities: Sequence[float] = None,

120

dt: float = 1e-8,

121

**kwargs

122

) -> ParametricFunction:

123

"""

124

Plot a mathematical function f(x) -> y.

125

126

Parameters:

127

- function: Function to plot, taking x and returning y

128

- x_range: Domain [x_min, x_max, x_step] (uses axis range if None)

129

- use_vectorized: Whether function accepts numpy arrays

130

- discontinuities: x-values where function is discontinuous

131

- dt: Tolerance around discontinuities

132

133

Returns:

134

- ParametricFunction: Plotted curve object

135

"""

136

137

def plot_parametric_curve(

138

function: Callable[[float], Sequence[float]],

139

t_range: Sequence[float] = None,

140

**kwargs

141

) -> ParametricFunction:

142

"""

143

Plot parametric curve with function(t) -> [x(t), y(t)].

144

145

Parameters:

146

- function: Parametric function taking t, returning [x, y]

147

- t_range: Parameter domain [t_min, t_max, t_step]

148

149

Returns:

150

- ParametricFunction: Plotted parametric curve

151

"""

152

153

def plot_implicit_curve(

154

func: Callable[[float, float], float],

155

min_depth: int = 5,

156

max_quads: int = 1500,

157

**kwargs

158

) -> ImplicitFunction:

159

"""

160

Plot implicit curve defined by f(x,y) = 0.

161

162

Parameters:

163

- func: Function f(x,y) defining the curve

164

- min_depth: Minimum recursive subdivision depth

165

- max_quads: Maximum number of quadrilaterals for approximation

166

167

Returns:

168

- ImplicitFunction: Plotted implicit curve

169

"""

170

171

def get_graph(

172

function: Callable[[float], float],

173

x_range: Sequence[float] = None,

174

**kwargs

175

) -> ParametricFunction:

176

"""Alias for plot() method - plot mathematical function."""

177

178

# Grid and reference lines

179

def get_horizontal_line(

180

point: np.ndarray,

181

line_func: Callable = Line,

182

line_config: dict = None,

183

**kwargs

184

) -> Line:

185

"""

186

Create horizontal reference line through given point.

187

188

Parameters:

189

- point: Point to draw horizontal line through

190

- line_func: Line class to use (Line, DashedLine, etc.)

191

- line_config: Configuration for the line

192

193

Returns:

194

- Line: Horizontal reference line

195

"""

196

197

def get_vertical_line(

198

point: np.ndarray,

199

line_func: Callable = Line,

200

line_config: dict = None,

201

**kwargs

202

) -> Line:

203

"""

204

Create vertical reference line through given point.

205

206

Parameters:

207

- point: Point to draw vertical line through

208

- line_func: Line class to use

209

- line_config: Configuration for the line

210

211

Returns:

212

- Line: Vertical reference line

213

"""

214

215

def get_lines_to_point(

216

point: np.ndarray,

217

**kwargs

218

) -> VGroup:

219

"""

220

Get both horizontal and vertical lines to a point.

221

222

Parameters:

223

- point: Target point for reference lines

224

225

Returns:

226

- VGroup: Both horizontal and vertical reference lines

227

"""

228

229

# Axis labels and decorations

230

def get_x_axis_label(

231

label: str | Mobject,

232

edge: np.ndarray = RIGHT,

233

direction: np.ndarray = DL,

234

**kwargs

235

) -> Mobject:

236

"""

237

Create label for x-axis.

238

239

Parameters:

240

- label: Label text or mobject

241

- edge: Which edge of axis to place label

242

- direction: Direction to offset label from axis

243

244

Returns:

245

- Mobject: Positioned x-axis label

246

"""

247

248

def get_y_axis_label(

249

label: str | Mobject,

250

edge: np.ndarray = UP,

251

direction: np.ndarray = UR,

252

**kwargs

253

) -> Mobject:

254

"""

255

Create label for y-axis.

256

257

Parameters:

258

- label: Label text or mobject

259

- edge: Which edge of axis to place label

260

- direction: Direction to offset label from axis

261

262

Returns:

263

- Mobject: Positioned y-axis label

264

"""

265

266

def get_axis_labels(

267

x_label: str | Mobject = "x",

268

y_label: str | Mobject = "y"

269

) -> VGroup:

270

"""

271

Get both x and y axis labels.

272

273

Parameters:

274

- x_label: X-axis label

275

- y_label: Y-axis label

276

277

Returns:

278

- VGroup: Both axis labels

279

"""

280

281

# Coordinate transformations

282

def angle_of_tangent(

283

x: float,

284

graph: ParametricFunction,

285

dx: float = 1e-8

286

) -> float:

287

"""

288

Get angle of tangent to graph at x-coordinate.

289

290

Parameters:

291

- x: X-coordinate for tangent

292

- graph: Function graph to find tangent on

293

- dx: Small increment for numerical differentiation

294

295

Returns:

296

- float: Tangent angle in radians

297

"""

298

299

def slope_of_tangent(

300

x: float,

301

graph: ParametricFunction,

302

**kwargs

303

) -> float:

304

"""

305

Get slope of tangent to graph at x-coordinate.

306

307

Parameters:

308

- x: X-coordinate for tangent

309

- graph: Function graph to find tangent on

310

311

Returns:

312

- float: Tangent slope (dy/dx)

313

"""

314

315

def input_to_graph_point(

316

x: float,

317

graph: ParametricFunction

318

) -> np.ndarray:

319

"""

320

Get point on graph corresponding to x-coordinate.

321

322

Parameters:

323

- x: Input x-coordinate

324

- graph: Function graph to sample

325

326

Returns:

327

- np.ndarray: Point [x, f(x), 0] on the graph

328

"""

329

330

# Area and integration visualization

331

def get_riemann_rectangles(

332

graph: ParametricFunction,

333

x_range: Sequence[float] = None,

334

dx: float = 0.1,

335

input_sample_type: str = "left",

336

stroke_width: float = 1,

337

stroke_color: str = BLACK,

338

fill_opacity: float = 1,

339

color: Sequence[str] = (BLUE, GREEN),

340

show_signed_area: bool = True,

341

bounded_graph: ParametricFunction = None,

342

blend: bool = False,

343

width_scale_factor: float = 1.001

344

) -> VGroup:

345

"""

346

Create Riemann rectangles for numerical integration visualization.

347

348

Parameters:

349

- graph: Function to integrate

350

- x_range: Integration domain [x_min, x_max]

351

- dx: Width of each rectangle

352

- input_sample_type: Sampling method ("left", "right", "center")

353

- stroke_width: Rectangle border width

354

- stroke_color: Rectangle border color

355

- fill_opacity: Rectangle fill opacity

356

- color: Colors for positive/negative areas

357

- show_signed_area: Whether to show negative areas differently

358

- bounded_graph: Lower bound function (default is x-axis)

359

- blend: Whether to blend colors across rectangles

360

- width_scale_factor: Rectangle width adjustment

361

362

Returns:

363

- VGroup: Collection of Riemann rectangles

364

"""

365

366

def get_area(

367

graph: ParametricFunction,

368

x_range: Sequence[float] = None,

369

color: str | Sequence[str] = (BLUE, GREEN),

370

opacity: float = 0.3,

371

bounded_graph: ParametricFunction = None,

372

**kwargs

373

) -> Polygon:

374

"""

375

Create filled area under/between curves.

376

377

Parameters:

378

- graph: Upper boundary function

379

- x_range: Integration domain [x_min, x_max]

380

- color: Fill color(s)

381

- opacity: Fill opacity

382

- bounded_graph: Lower boundary function (default is x-axis)

383

384

Returns:

385

- Polygon: Filled area region

386

"""

387

388

class ThreeDAxes(Axes):

389

"""

390

3D Cartesian coordinate system extending 2D axes with z-axis.

391

392

Provides full 3D coordinate system with x, y, and z axes for

393

3D function plotting and spatial visualizations.

394

"""

395

396

def __init__(

397

x_range: Sequence[float] = (-6, 6, 1),

398

y_range: Sequence[float] = (-5, 5, 1),

399

z_range: Sequence[float] = (-4, 4, 1),

400

x_length: float = config["frame_width"],

401

y_length: float = config["frame_height"],

402

z_length: float = 3.0,

403

z_axis_config: dict = None,

404

z_normal: np.ndarray = DOWN,

405

num_axis_pieces: int = 20,

406

light_source: np.ndarray = 9 * DOWN + 7 * LEFT + 10 * OUT,

407

**kwargs

408

) -> None:

409

"""

410

Parameters:

411

- x_range: [x_min, x_max, x_step] for x-axis

412

- y_range: [y_min, y_max, y_step] for y-axis

413

- z_range: [z_min, z_max, z_step] for z-axis

414

- x_length: Physical x-axis length

415

- y_length: Physical y-axis length

416

- z_length: Physical z-axis length

417

- z_axis_config: Configuration specific to z-axis

418

- z_normal: Normal direction for z-axis display

419

- num_axis_pieces: Number of pieces for smooth shading

420

- light_source: Light position for 3D shading

421

"""

422

423

def get_z_axis_label(

424

label: str | Mobject,

425

edge: np.ndarray = OUT,

426

direction: np.ndarray = RIGHT,

427

**kwargs

428

) -> Mobject:

429

"""Create label for z-axis."""

430

431

def get_z_range() -> Sequence[float]:

432

"""Get z-axis range [min, max, step]."""

433

434

def get_z_length() -> float:

435

"""Get physical z-axis length."""

436

```

437

438

### Specialized Coordinate Systems

439

440

Advanced coordinate systems for specific mathematical contexts and specialized visualizations.

441

442

```python { .api }

443

class NumberPlane(Axes):

444

"""

445

2D coordinate plane with background grid lines and enhanced visual aids.

446

447

Extends basic axes with visible grid lines, background coloring,

448

and enhanced visual feedback for coordinate-based work.

449

"""

450

451

def __init__(

452

x_range: Sequence[float] = None,

453

y_range: Sequence[float] = None,

454

x_length: float = None,

455

y_length: float = None,

456

background_line_style: dict = None,

457

faded_line_style: dict = None,

458

faded_line_ratio: int = 1,

459

make_smooth_after_applying_functions: bool = True,

460

**kwargs

461

) -> None:

462

"""

463

Parameters:

464

- x_range: X-axis range and step

465

- y_range: Y-axis range and step

466

- x_length: Physical width

467

- y_length: Physical height

468

- background_line_style: Style for background grid lines

469

- faded_line_style: Style for fainter grid lines

470

- faded_line_ratio: Ratio of faded to normal lines

471

- make_smooth_after_applying_functions: Auto-smooth transformations

472

"""

473

474

def get_lines_parallel_to_axis(

475

axis: NumberLine,

476

line_func: Callable = Line,

477

freq: int = 1,

478

**line_kwargs

479

) -> VGroup:

480

"""

481

Create grid lines parallel to specified axis.

482

483

Parameters:

484

- axis: Axis to create parallel lines for

485

- line_func: Type of line to create

486

- freq: Frequency of lines (every nth tick)

487

488

Returns:

489

- VGroup: Parallel grid lines

490

"""

491

492

def get_coordinate_labels(

493

x_vals: Sequence[float] = None,

494

y_vals: Sequence[float] = None,

495

**kwargs

496

) -> VDict:

497

"""

498

Create coordinate labels for grid intersection points.

499

500

Parameters:

501

- x_vals: X-coordinates to label

502

- y_vals: Y-coordinates to label

503

504

Returns:

505

- VDict: Coordinate labels indexed by position

506

"""

507

508

class PolarPlane(Axes):

509

"""

510

Polar coordinate system with radial and angular grid lines.

511

512

Specialized for polar functions r(θ) with circular grid lines

513

and angular divisions for polar mathematical contexts.

514

"""

515

516

def __init__(

517

radius_max: float = config["frame_y_radius"],

518

radius_step: float = 1,

519

size: float = None,

520

azimuth_step: float = PI / 12,

521

azimuth_units: str = "PI",

522

azimuth_compact_fraction: bool = True,

523

azimuth_offset: float = 0,

524

azimuth_direction: str = "CCW",

525

azimuth_label_buff: float = SMALL_BUFF,

526

azimuth_label_font_size: float = 20,

527

radius_config: dict = None,

528

**kwargs

529

) -> None:

530

"""

531

Parameters:

532

- radius_max: Maximum radius for polar grid

533

- radius_step: Step size between radial grid lines

534

- size: Overall size of polar plane

535

- azimuth_step: Angular step between radial lines

536

- azimuth_units: Units for angle labels ("PI", "degrees")

537

- azimuth_compact_fraction: Whether to use compact fractions

538

- azimuth_offset: Angular offset for zero direction

539

- azimuth_direction: Direction of angle increase ("CCW", "CW")

540

- azimuth_label_buff: Buffer for angle labels

541

- azimuth_label_font_size: Font size for angle labels

542

- radius_config: Configuration for radial axis

543

"""

544

545

def polar_to_point(

546

radius: float,

547

azimuth: float

548

) -> np.ndarray:

549

"""

550

Convert polar coordinates to Cartesian point.

551

552

Parameters:

553

- radius: Radial distance

554

- azimuth: Angle in radians

555

556

Returns:

557

- np.ndarray: Cartesian point [x, y, 0]

558

"""

559

560

def point_to_polar(

561

point: np.ndarray

562

) -> tuple[float, float]:

563

"""

564

Convert Cartesian point to polar coordinates.

565

566

Parameters:

567

- point: Cartesian point

568

569

Returns:

570

- tuple: (radius, azimuth) in polar coordinates

571

"""

572

573

def pr2pt(radius: float, azimuth: float) -> np.ndarray:

574

"""Alias for polar_to_point."""

575

576

def pt2pr(point: np.ndarray) -> tuple[float, float]:

577

"""Alias for point_to_polar."""

578

579

class ComplexPlane(NumberPlane):

580

"""

581

Complex number plane with real and imaginary axes.

582

583

Specialized coordinate system for complex analysis with

584

appropriate labeling and visualization for complex functions.

585

"""

586

587

def __init__(

588

x_range: Sequence[float] = (-4, 4, 1),

589

y_range: Sequence[float] = (-4, 4, 1),

590

**kwargs

591

) -> None:

592

"""

593

Parameters:

594

- x_range: Real axis range

595

- y_range: Imaginary axis range

596

"""

597

598

def number_to_point(

599

number: complex | float

600

) -> np.ndarray:

601

"""

602

Convert complex number to point on plane.

603

604

Parameters:

605

- number: Complex number z = a + bi

606

607

Returns:

608

- np.ndarray: Point [Re(z), Im(z), 0]

609

"""

610

611

def point_to_number(

612

point: np.ndarray

613

) -> complex:

614

"""

615

Convert point on plane to complex number.

616

617

Parameters:

618

- point: Cartesian point

619

620

Returns:

621

- complex: Complex number a + bi

622

"""

623

624

def n2p(number: complex | float) -> np.ndarray:

625

"""Alias for number_to_point."""

626

627

def p2n(point: np.ndarray) -> complex:

628

"""Alias for point_to_number."""

629

```

630

631

### Number Lines

632

633

One-dimensional coordinate systems for number representation, intervals, and linear mathematical concepts.

634

635

```python { .api }

636

class NumberLine(Line):

637

"""

638

One-dimensional number line with ticks, labels, and number positioning.

639

640

Fundamental 1D coordinate system for representing real numbers,

641

intervals, and linear mathematical relationships.

642

"""

643

644

def __init__(

645

x_range: Sequence[float] = (-8, 8, 1),

646

length: float = None,

647

unit_size: float = 1,

648

include_ticks: bool = True,

649

tick_size: float = 0.1,

650

numbers_with_elongated_ticks: Sequence[float] = None,

651

longer_tick_multiple: float = 2,

652

exclude_zero_from_default_numbers: bool = False,

653

numbers_to_show: Sequence[float] = None,

654

numbers_to_exclude: Sequence[float] = None,

655

label_direction: np.ndarray = DOWN,

656

line_to_number_buff: float = MED_SMALL_BUFF,

657

include_numbers: bool = False,

658

scaling: _ScaleBase = LinearBase(),

659

font_size: float = 36,

660

stroke_width: float = 2,

661

include_tip: bool = False,

662

tip_width: float = 0.25,

663

tip_height: float = 0.25,

664

decimal_number_config: dict = None,

665

numbers_config: dict = None,

666

**kwargs

667

) -> None:

668

"""

669

Parameters:

670

- x_range: [min, max, step] for number line range

671

- length: Physical length of number line

672

- unit_size: Manim units per number line unit

673

- include_ticks: Whether to show tick marks

674

- tick_size: Height of tick marks

675

- numbers_with_elongated_ticks: Numbers with longer ticks

676

- longer_tick_multiple: Length multiplier for elongated ticks

677

- exclude_zero_from_default_numbers: Whether to skip zero label

678

- numbers_to_show: Specific numbers to label

679

- numbers_to_exclude: Numbers to skip in labeling

680

- label_direction: Direction to place number labels

681

- line_to_number_buff: Space between line and labels

682

- include_numbers: Whether to show number labels

683

- scaling: Scaling transformation for the line

684

- font_size: Size of number labels

685

- stroke_width: Line thickness

686

- include_tip: Whether to show arrow tip

687

- tip_width: Arrow tip width

688

- tip_height: Arrow tip height

689

- decimal_number_config: Config for decimal number labels

690

- numbers_config: Config for number label mobjects

691

"""

692

693

def number_to_point(number: float) -> np.ndarray:

694

"""Convert number to position on the line."""

695

696

def point_to_number(point: np.ndarray) -> float:

697

"""Convert position on line to number."""

698

699

def n2p(number: float) -> np.ndarray:

700

"""Alias for number_to_point."""

701

702

def p2n(point: np.ndarray) -> float:

703

"""Alias for point_to_number."""

704

705

def get_number_mobject(

706

number: float,

707

**number_config

708

) -> DecimalNumber:

709

"""

710

Create mobject for displaying a number.

711

712

Parameters:

713

- number: Number to display

714

- **number_config: Configuration for number formatting

715

716

Returns:

717

- DecimalNumber: Formatted number mobject

718

"""

719

720

def get_tick(

721

x: float,

722

size: float = None

723

) -> Line:

724

"""

725

Create tick mark at specified position.

726

727

Parameters:

728

- x: Number position for tick

729

- size: Tick mark height

730

731

Returns:

732

- Line: Tick mark line

733

"""

734

735

def add_ticks() -> Self:

736

"""Add tick marks to the number line."""

737

738

def add_numbers(

739

*numbers: float,

740

**kwargs

741

) -> Self:

742

"""

743

Add number labels to the line.

744

745

Parameters:

746

- *numbers: Numbers to label (uses default range if empty)

747

"""

748

749

class UnitInterval(NumberLine):

750

"""

751

Number line representing the unit interval [0, 1].

752

753

Specialized for probability, unit measurements, and

754

normalized value representations.

755

"""

756

757

def __init__(

758

x_range: Sequence[float] = (0, 1, 0.1),

759

**kwargs

760

) -> None:

761

"""

762

Parameters:

763

- x_range: Range for unit interval (default [0,1,0.1])

764

"""

765

```

766

767

### Function Plotting

768

769

Mathematical function visualization with support for parametric, implicit, and standard function plotting with advanced rendering options.

770

771

```python { .api }

772

class ParametricFunction(VMobject):

773

"""

774

Parametric curve defined by function(t) -> [x(t), y(t), z(t)].

775

776

General-purpose curve plotting for parametric equations,

777

space curves, and complex mathematical paths.

778

"""

779

780

def __init__(

781

function: Callable[[float], Sequence[float]],

782

t_range: Sequence[float] = (0, 1, 0.01),

783

scaling: _ScaleBase = LinearBase(),

784

use_smoothing: bool = True,

785

use_vectorized: bool = False,

786

discontinuities: Sequence[float] = None,

787

dt: float = 1e-8,

788

**kwargs

789

) -> None:

790

"""

791

Parameters:

792

- function: Parametric function t -> [x(t), y(t), z(t)]

793

- t_range: Parameter domain [t_min, t_max, t_step]

794

- scaling: Coordinate scaling transformation

795

- use_smoothing: Whether to smooth the resulting curve

796

- use_vectorized: Whether function accepts array input

797

- discontinuities: t-values where function is discontinuous

798

- dt: Tolerance around discontinuities

799

"""

800

801

class FunctionGraph(ParametricFunction):

802

"""

803

Standard function graph y = f(x) with automatic parametrization.

804

805

Convenient wrapper for plotting functions of one variable

806

with domain/range validation and optimization.

807

"""

808

809

def __init__(

810

function: Callable[[float], float],

811

x_range: Sequence[float] = (-8, 8, 0.25),

812

color: str = YELLOW,

813

**kwargs

814

) -> None:

815

"""

816

Parameters:

817

- function: Function f(x) -> y

818

- x_range: Domain [x_min, x_max, x_step]

819

- color: Graph color

820

"""

821

822

class ImplicitFunction(VMobject):

823

"""

824

Implicit curve defined by equation f(x, y) = 0.

825

826

Specialized for level curves, implicit equations, and

827

relationships that cannot be expressed as y = f(x).

828

"""

829

830

def __init__(

831

func: Callable[[float, float], float],

832

x_range: Sequence[float] = (-8, 8),

833

y_range: Sequence[float] = (-4, 4),

834

min_depth: int = 5,

835

max_quads: int = 1500,

836

use_smoothing: bool = True,

837

joint_type: str = "no_joint",

838

**kwargs

839

) -> None:

840

"""

841

Parameters:

842

- func: Implicit function f(x,y) defining curve where f(x,y) = 0

843

- x_range: X domain [x_min, x_max]

844

- y_range: Y domain [y_min, y_max]

845

- min_depth: Minimum subdivision depth for curve tracing

846

- max_quads: Maximum quadrilaterals for curve approximation

847

- use_smoothing: Whether to smooth the resulting curve

848

- joint_type: How to handle curve segment connections

849

"""

850

```

851

852

## Usage Examples

853

854

### Basic Coordinate System

855

856

```python

857

from manim import *

858

859

class CoordinateExample(Scene):

860

def construct(self):

861

# Create 2D axes

862

axes = Axes(

863

x_range=[-3, 3, 1],

864

y_range=[-2, 2, 0.5],

865

x_length=10,

866

y_length=6,

867

axis_config={"color": BLUE},

868

x_axis_config={"numbers_to_include": np.arange(-3, 4, 1)},

869

y_axis_config={"numbers_to_include": np.arange(-2, 2.5, 0.5)},

870

tips=False

871

)

872

873

# Add axis labels

874

x_label = axes.get_x_axis_label("x")

875

y_label = axes.get_y_axis_label("y", direction=LEFT)

876

877

# Plot function

878

graph = axes.plot(lambda x: x**2, color=YELLOW)

879

880

self.add(axes, x_label, y_label, graph)

881

```

882

883

### Function Plotting

884

885

```python

886

class FunctionPlotExample(Scene):

887

def construct(self):

888

axes = Axes(

889

x_range=[-4, 4, 1],

890

y_range=[-2, 8, 1],

891

x_length=8,

892

y_length=6

893

)

894

895

# Plot multiple functions

896

functions = [

897

(lambda x: x**2, RED, "x²"),

898

(lambda x: 2**x, BLUE, "2ˣ"),

899

(lambda x: np.sin(x) + 3, GREEN, "sin(x) + 3")

900

]

901

902

graphs = VGroup()

903

labels = VGroup()

904

905

for func, color, label_text in functions:

906

graph = axes.plot(func, color=color)

907

label = MathTex(label_text, color=color).scale(0.7)

908

graphs.add(graph)

909

labels.add(label)

910

911

# Position labels

912

labels.arrange(RIGHT, buff=1).to_edge(UP)

913

914

self.add(axes, graphs, labels)

915

```

916

917

### 3D Coordinate System

918

919

```python

920

class ThreeDAxesExample(ThreeDScene):

921

def construct(self):

922

# Create 3D axes

923

axes = ThreeDAxes(

924

x_range=[-5, 5, 1],

925

y_range=[-5, 5, 1],

926

z_range=[-3, 3, 1],

927

x_length=8,

928

y_length=8,

929

z_length=6

930

)

931

932

# Add axis labels

933

x_label = axes.get_x_axis_label("x")

934

y_label = axes.get_y_axis_label("y")

935

z_label = axes.get_z_axis_label("z")

936

937

# Plot 3D parametric curve

938

curve = axes.plot_parametric_curve(

939

lambda t: [2*np.cos(t), 2*np.sin(t), t/2],

940

t_range=[0, 4*PI, 0.1],

941

color=YELLOW

942

)

943

944

# Set camera orientation

945

self.set_camera_orientation(phi=75*DEGREES, theta=45*DEGREES)

946

947

self.add(axes, x_label, y_label, z_label, curve)

948

```

949

950

### Polar Coordinates

951

952

```python

953

class PolarExample(Scene):

954

def construct(self):

955

# Create polar plane

956

plane = PolarPlane(

957

radius_max=4,

958

radius_step=1,

959

azimuth_step=PI/6,

960

azimuth_units="PI"

961

)

962

963

# Plot polar function r = 2 + cos(3θ)

964

polar_graph = plane.plot_polar_graph(

965

lambda theta: 2 + np.cos(3*theta),

966

[0, 2*PI],

967

color=RED

968

)

969

970

self.add(plane, polar_graph)

971

```

972

973

### Advanced Plotting Features

974

975

```python

976

class AdvancedPlottingExample(Scene):

977

def construct(self):

978

axes = Axes(x_range=[-3, 3, 1], y_range=[-1, 3, 1])

979

980

# Plot function with area highlighting

981

func = lambda x: x**2

982

graph = axes.plot(func, color=BLUE)

983

984

# Add Riemann rectangles

985

riemann_rects = axes.get_riemann_rectangles(

986

graph,

987

x_range=[-2, 2],

988

dx=0.2,

989

color=[BLUE_D, BLUE_E]

990

)

991

992

# Add area under curve

993

area = axes.get_area(

994

graph,

995

x_range=[-1, 1],

996

color=YELLOW,

997

opacity=0.5

998

)

999

1000

# Add reference lines

1001

point = axes.coords_to_point(1, 1)

1002

h_line = axes.get_horizontal_line(point, color=GREEN)

1003

v_line = axes.get_vertical_line(point, color=GREEN)

1004

dot = Dot(point, color=RED)

1005

1006

self.add(axes, graph, riemann_rects, area, h_line, v_line, dot)

1007

```