or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

3d-objects.mdadvanced-animations.mdanimation-system.mdboolean-operations.mdcoordinate-systems.mdindex.mdinteractive-controls.mdmathematical-objects.mdmatrix-visualization.mdprobability-stats.mdscene-framework.mdtext-and-latex.mdutilities-and-constants.mdvalue-tracking.mdvector-fields.md

coordinate-systems.mddocs/

0

# Coordinate Systems and Graphs

1

2

ManimGL provides comprehensive coordinate system support including 2D and 3D axes, number lines, complex planes, and function plotting capabilities. These tools enable precise mathematical visualization and graph-based animations.

3

4

## Capabilities

5

6

### 2D Coordinate Systems

7

8

Standard Cartesian coordinate systems with customizable ranges, styling, and labeling.

9

10

```python { .api }

11

class Axes(VGroup):

12

def __init__(self, x_range=(-8, 8, 1), y_range=(-6, 6, 1), **kwargs):

13

"""

14

2D Cartesian coordinate axes.

15

16

Parameters:

17

- x_range: tuple, (x_min, x_max, x_step) for x-axis

18

- y_range: tuple, (y_min, y_max, y_step) for y-axis

19

- axis_config: dict, styling for both axes

20

- x_axis_config: dict, x-axis specific styling

21

- y_axis_config: dict, y-axis specific styling

22

- tips: bool, show axis arrows (default: True)

23

- tip_shape: ArrowTip class for axis ends

24

- include_ticks: bool, show tick marks

25

- tick_size: float, tick mark length

26

- include_numbers: bool, show axis labels

27

- numbers_with_elongated_ticks: list, which numbers get longer ticks

28

- numbers_to_exclude: list, numbers to skip labeling

29

- label_direction: np.array, direction for axis labels

30

"""

31

32

def plot(self, function, x_range=None, **kwargs):

33

"""

34

Plot a function on the coordinate system.

35

36

Parameters:

37

- function: callable, function to plot f(x) -> y

38

- x_range: tuple, (x_min, x_max, x_step) or None for axes range

39

- color: curve color

40

- stroke_width: curve thickness

41

- discontinuities: list, x-values where function is discontinuous

42

- dt: float, sampling interval for plotting

43

44

Returns:

45

ParametricCurve

46

"""

47

48

def get_graph(self, func, x_range=None, **kwargs):

49

"""

50

Alias for plot() method.

51

52

Parameters:

53

- func: callable, function to plot

54

- x_range: tuple, domain for plotting

55

56

Returns:

57

ParametricCurve

58

"""

59

60

def input_to_graph_point(self, x, graph):

61

"""

62

Convert x-coordinate to point on graph.

63

64

Parameters:

65

- x: float, input value

66

- graph: ParametricCurve, graph object

67

68

Returns:

69

np.array, point on graph

70

"""

71

72

def point_to_coords(self, point):

73

"""

74

Convert scene point to coordinate values.

75

76

Parameters:

77

- point: np.array, point in scene coordinates

78

79

Returns:

80

tuple, (x, y) coordinate values

81

"""

82

83

def coords_to_point(self, x, y):

84

"""

85

Convert coordinate values to scene point.

86

87

Parameters:

88

- x: float, x-coordinate

89

- y: float, y-coordinate

90

91

Returns:

92

np.array, point in scene coordinates

93

"""

94

95

def get_axis_labels(self, x_label="x", y_label="y"):

96

"""

97

Create axis labels.

98

99

Parameters:

100

- x_label: str or Mobject, x-axis label

101

- y_label: str or Mobject, y-axis label

102

103

Returns:

104

VGroup containing labels

105

"""

106

107

def get_axis_label(self, label, axis, edge, direction):

108

"""

109

Create single axis label.

110

111

Parameters:

112

- label: str or Mobject, label content

113

- axis: Line, axis object

114

- edge: np.array, axis edge for positioning

115

- direction: np.array, label offset direction

116

117

Returns:

118

Mobject

119

"""

120

121

def add_coordinate_labels(self, x_values=None, y_values=None):

122

"""

123

Add coordinate labels to axes.

124

125

Parameters:

126

- x_values: list, x-coordinates to label

127

- y_values: list, y-coordinates to label

128

129

Returns:

130

VGroup containing all labels

131

"""

132

133

class NumberPlane(Axes):

134

def __init__(self, x_range=(-8, 8, 1), y_range=(-6, 6, 1), **kwargs):

135

"""

136

2D coordinate plane with grid lines.

137

138

Parameters:

139

- x_range: tuple, x-axis range and step

140

- y_range: tuple, y-axis range and step

141

- background_line_style: dict, grid line styling

142

- faded_line_style: dict, secondary grid line styling

143

- faded_line_ratio: int, ratio of faded to normal lines

144

- make_smooth_after_applying_functions: bool, smooth after transforms

145

"""

146

147

def get_lines_parallel_to_axis(self, axis, freq=1, **kwargs):

148

"""

149

Create grid lines parallel to specified axis.

150

151

Parameters:

152

- axis: Line, reference axis

153

- freq: float, line frequency

154

155

Returns:

156

VGroup of grid lines

157

"""

158

159

def get_vector(self, coords, **kwargs):

160

"""

161

Create vector arrow from origin to coordinates.

162

163

Parameters:

164

- coords: tuple or list, (x, y) coordinates

165

- **kwargs: Arrow styling parameters

166

167

Returns:

168

Arrow

169

"""

170

171

def prepare_for_nonlinear_transform(self, num_inserted_curves=50):

172

"""

173

Prepare plane for nonlinear transformations.

174

175

Parameters:

176

- num_inserted_curves: int, number of interpolation curves

177

178

Returns:

179

NumberPlane (self)

180

"""

181

```

182

183

### Complex Number Plane

184

185

Specialized coordinate system for complex number visualization.

186

187

```python { .api }

188

class ComplexPlane(NumberPlane):

189

def __init__(self, **kwargs):

190

"""

191

Complex number coordinate plane.

192

193

Parameters:

194

- color: axis and grid color

195

- unit_size: float, size of unit square

196

- real_unit_size: float, real axis unit size

197

- imaginary_unit_size: float, imaginary axis unit size

198

"""

199

200

def number_to_point(self, number):

201

"""

202

Convert complex number to scene point.

203

204

Parameters:

205

- number: complex, complex number

206

207

Returns:

208

np.array, corresponding scene point

209

"""

210

211

def point_to_number(self, point):

212

"""

213

Convert scene point to complex number.

214

215

Parameters:

216

- point: np.array, scene point

217

218

Returns:

219

complex

220

"""

221

222

def get_default_coordinate_values(self):

223

"""

224

Get default coordinate labeling values.

225

226

Returns:

227

tuple, (real_values, imaginary_values)

228

"""

229

230

def add_coordinate_labels(self, **kwargs):

231

"""

232

Add complex number coordinate labels.

233

234

Returns:

235

VGroup containing labels

236

"""

237

```

238

239

### 3D Coordinate Systems

240

241

Three-dimensional coordinate systems with depth and perspective support.

242

243

```python { .api }

244

class ThreeDAxes(Axes):

245

def __init__(self, x_range=(-6, 6, 1), y_range=(-5, 5, 1), z_range=(-4, 4, 1), **kwargs):

246

"""

247

3D Cartesian coordinate axes.

248

249

Parameters:

250

- x_range: tuple, x-axis range and step

251

- y_range: tuple, y-axis range and step

252

- z_range: tuple, z-axis range and step

253

- num_axis_pieces: int, pieces per axis for 3D rendering

254

- light_source: np.array, 3D lighting direction

255

"""

256

257

def coords_to_point(self, x, y, z):

258

"""

259

Convert 3D coordinates to scene point.

260

261

Parameters:

262

- x: float, x-coordinate

263

- y: float, y-coordinate

264

- z: float, z-coordinate

265

266

Returns:

267

np.array, scene point with 3D projection

268

"""

269

270

def point_to_coords(self, point):

271

"""

272

Convert scene point to 3D coordinates.

273

274

Parameters:

275

- point: np.array, scene point

276

277

Returns:

278

tuple, (x, y, z) coordinates

279

"""

280

281

def get_z_axis_label(self, label="z", **kwargs):

282

"""

283

Create z-axis label.

284

285

Parameters:

286

- label: str or Mobject, z-axis label

287

288

Returns:

289

Mobject

290

"""

291

```

292

293

### Number Lines

294

295

One-dimensional number lines with customizable ranges and tick marks.

296

297

```python { .api }

298

class NumberLine(Line):

299

def __init__(self, x_range=(-8, 8, 1), **kwargs):

300

"""

301

One-dimensional number line.

302

303

Parameters:

304

- x_range: tuple, (min, max, step) for number line

305

- unit_size: float, distance per unit

306

- include_ticks: bool, show tick marks

307

- tick_size: float, tick mark length

308

- include_numbers: bool, show number labels

309

- numbers_with_elongated_ticks: list, numbers with longer ticks

310

- numbers_to_exclude: list, numbers to skip

311

- label_direction: np.array, direction for number labels

312

- line_to_number_buff: float, spacing between line and labels

313

- decimal_number_config: dict, DecimalNumber styling

314

- exclude_zero_from_default_numbers: bool, hide zero label

315

"""

316

317

def number_to_point(self, number):

318

"""

319

Convert number to point on line.

320

321

Parameters:

322

- number: float, number value

323

324

Returns:

325

np.array, corresponding point on line

326

"""

327

328

def point_to_number(self, point):

329

"""

330

Convert point to number value.

331

332

Parameters:

333

- point: np.array, point on or near line

334

335

Returns:

336

float, corresponding number

337

"""

338

339

def get_tick(self, x, size=None):

340

"""

341

Create tick mark at specified position.

342

343

Parameters:

344

- x: float, position for tick

345

- size: float, tick length

346

347

Returns:

348

Line, tick mark

349

"""

350

351

def get_tick_marks(self):

352

"""

353

Create all tick marks for the number line.

354

355

Returns:

356

VGroup of tick marks

357

"""

358

359

def add_numbers(self, x_values=None, **kwargs):

360

"""

361

Add number labels to the line.

362

363

Parameters:

364

- x_values: list, specific numbers to label

365

366

Returns:

367

VGroup of number labels

368

"""

369

```

370

371

### Function Graphs and Curves

372

373

Objects for plotting mathematical functions and parametric curves.

374

375

```python { .api }

376

class FunctionGraph(ParametricCurve):

377

def __init__(self, function, x_range=(-8, 8), **kwargs):

378

"""

379

Graph of mathematical function y = f(x).

380

381

Parameters:

382

- function: callable, function to plot f(x) -> y

383

- x_range: tuple, (x_min, x_max) domain

384

- color: curve color

385

- stroke_width: curve thickness

386

- discontinuities: list, x-values with discontinuities

387

- dt: float, sampling resolution

388

"""

389

390

class ParametricCurve(VMobject):

391

def __init__(self, function, t_range=(0, 1), **kwargs):

392

"""

393

Parametric curve r(t) = (x(t), y(t), z(t)).

394

395

Parameters:

396

- function: callable, parametric function t -> (x, y, z)

397

- t_range: tuple, (t_min, t_max) parameter range

398

- dt: float, parameter sampling step

399

- discontinuities: list, t-values with discontinuities

400

"""

401

402

def get_point_from_function(self, t):

403

"""

404

Get point on curve at parameter value t.

405

406

Parameters:

407

- t: float, parameter value

408

409

Returns:

410

np.array, point on curve

411

"""

412

413

class ImplicitFunction(VMobject):

414

def __init__(self, func, x_range=(-8, 8), y_range=(-6, 6), **kwargs):

415

"""

416

Implicit function curve F(x, y) = 0.

417

418

Parameters:

419

- func: callable, implicit function F(x, y) -> float

420

- x_range: tuple, x domain for plotting

421

- y_range: tuple, y domain for plotting

422

- resolution: int, grid resolution for level finding

423

- tolerance: float, zero-level tolerance

424

"""

425

```

426

427

## Usage Examples

428

429

### Basic Coordinate System

430

431

```python

432

from manimgl import *

433

434

class CoordinateExample(Scene):

435

def construct(self):

436

# Create coordinate system

437

axes = Axes(

438

x_range=(-5, 5, 1),

439

y_range=(-3, 3, 1),

440

axis_config={"color": WHITE}

441

)

442

443

# Add labels

444

labels = axes.get_axis_labels(x_label="x", y_label="y")

445

446

self.play(ShowCreation(axes))

447

self.play(Write(labels))

448

self.wait()

449

```

450

451

### Function Plotting

452

453

```python

454

class FunctionExample(Scene):

455

def construct(self):

456

axes = Axes(x_range=(-3, 3), y_range=(-2, 2))

457

458

# Plot functions

459

sin_graph = axes.plot(lambda x: np.sin(x), color=BLUE)

460

cos_graph = axes.plot(lambda x: np.cos(x), color=RED)

461

462

# Create labels

463

sin_label = MathTex("\\sin(x)").set_color(BLUE)

464

cos_label = MathTex("\\cos(x)").set_color(RED)

465

466

self.add(axes)

467

self.play(ShowCreation(sin_graph))

468

self.play(ShowCreation(cos_graph))

469

self.play(Write(sin_label), Write(cos_label))

470

self.wait()

471

```

472

473

### 3D Coordinate System

474

475

```python

476

class ThreeDExample(ThreeDScene):

477

def construct(self):

478

axes = ThreeDAxes(

479

x_range=(-3, 3),

480

y_range=(-3, 3),

481

z_range=(-2, 2)

482

)

483

484

# Set camera angle

485

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

486

487

self.play(ShowCreation(axes))

488

self.wait()

489

```

490

491

### Complex Plane

492

493

```python

494

class ComplexExample(Scene):

495

def construct(self):

496

plane = ComplexPlane()

497

498

# Plot complex numbers

499

z1 = 2 + 3j

500

z2 = -1 + 2j

501

502

dot1 = Dot(plane.number_to_point(z1), color=BLUE)

503

dot2 = Dot(plane.number_to_point(z2), color=RED)

504

505

label1 = MathTex("2 + 3i").next_to(dot1, UR)

506

label2 = MathTex("-1 + 2i").next_to(dot2, UL)

507

508

self.add(plane)

509

self.play(ShowCreation(dot1), Write(label1))

510

self.play(ShowCreation(dot2), Write(label2))

511

self.wait()

512

```

513

514

### Parametric Curve

515

516

```python

517

class ParametricExample(Scene):

518

def construct(self):

519

axes = Axes(x_range=(-3, 3), y_range=(-3, 3))

520

521

# Parametric curve (circle)

522

curve = ParametricCurve(

523

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

524

t_range=(0, TAU),

525

color=YELLOW

526

)

527

528

self.add(axes)

529

self.play(ShowCreation(curve))

530

self.wait()

531

```

532

533

### Interactive Graph Animation

534

535

```python

536

class GraphAnimation(Scene):

537

def construct(self):

538

axes = Axes(x_range=(-2, 2), y_range=(-1, 3))

539

540

# Animated function parameter

541

k_tracker = ValueTracker(1)

542

543

# Function that depends on k

544

def get_graph():

545

k = k_tracker.get_value()

546

return axes.plot(lambda x: k * x**2, color=BLUE)

547

548

graph = always_redraw(get_graph)

549

550

self.add(axes, graph)

551

self.play(k_tracker.animate.set_value(3), run_time=2)

552

self.play(k_tracker.animate.set_value(0.5), run_time=2)

553

self.wait()

554

```