Skip to content

Commit 3bd5672

Browse files
authored
Fixed docs for :meth:.Coordinate_system.add_coordinates and moved :class: ~.Code example (#1852)
* replace old with new * fix docs for .add_coordinates() * move Code's example above its Parameters
1 parent ed64149 commit 3bd5672

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

manim/mobject/coordinate_systems.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,12 @@ def add_coordinates(
281281
Optional[Iterable[float]], Union[Dict[float, Union[str, float, "Mobject"]]]
282282
],
283283
**kwargs,
284-
) -> VGroup:
284+
):
285285
"""Adds labels to the axes.
286286
287+
Parameters
288+
----------
289+
287290
axes_numbers
288291
The numbers to be added to the axes. Use ``None`` to represent an axis with default labels.
289292
@@ -298,7 +301,7 @@ def add_coordinates(
298301
ax.add_coordinates(x_labels, None, z_labels) # default y labels, custom x & z labels
299302
ax.add_coordinates(x_labels) # only x labels
300303
301-
..code-block:: python
304+
.. code-block:: python
302305
303306
# specifically control the position and value of the labels using a dict
304307
ax = Axes(x_range=[0, 7])
@@ -308,11 +311,6 @@ def add_coordinates(
308311
x_vals = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
309312
x_dict = dict(zip(x_pos, x_vals))
310313
ax.add_coordinates(x_dict)
311-
312-
Returns
313-
-------
314-
VGroup
315-
A :class:`VGroup` of the number mobjects.
316314
"""
317315

318316
self.coordinate_labels = VGroup()

manim/mobject/svg/code_mobject.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ class Code(VGroup):
4646
`weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
4747
:meth:`remove_invisible_chars` to resolve this issue.
4848
49+
Examples
50+
--------
51+
52+
Normal usage::
53+
54+
listing = Code(
55+
"helloworldcpp.cpp",
56+
tab_width=4,
57+
background_stroke_width=1,
58+
background_stroke_color=WHITE,
59+
insert_line_no=True,
60+
style=Code.styles_list[15],
61+
background="window",
62+
language="cpp",
63+
)
64+
65+
We can also render code passed as a string (but note that
66+
the language has to be specified in this case):
67+
68+
.. manim:: CodeFromString
69+
:save_last_frame:
70+
71+
class CodeFromString(Scene):
72+
def construct(self):
73+
code = '''from manim import Scene, Square
74+
75+
class FadeInSquare(Scene):
76+
def construct(self):
77+
s = Square()
78+
self.play(FadeIn(s))
79+
self.play(s.animate.scale(2))
80+
self.wait()
81+
'''
82+
rendered_code = Code(code=code, tab_width=4, background="window",
83+
language="Python", font="Monospace")
84+
self.add(rendered_code)
85+
4986
Parameters
5087
----------
5188
file_name : :class:`str`
@@ -101,42 +138,6 @@ class Code(VGroup):
101138
code : :class:`~.Paragraph`
102139
The highlighted code.
103140
104-
Examples
105-
--------
106-
Normal usage::
107-
108-
listing = Code(
109-
"helloworldcpp.cpp",
110-
tab_width=4,
111-
background_stroke_width=1,
112-
background_stroke_color=WHITE,
113-
insert_line_no=True,
114-
style=Code.styles_list[15],
115-
background="window",
116-
language="cpp",
117-
)
118-
119-
We can also render code passed as a string (but note that
120-
the language has to be specified in this case):
121-
122-
.. manim:: CodeFromString
123-
:save_last_frame:
124-
125-
class CodeFromString(Scene):
126-
def construct(self):
127-
code = '''from manim import Scene, Square
128-
129-
class FadeInSquare(Scene):
130-
def construct(self):
131-
s = Square()
132-
self.play(FadeIn(s))
133-
self.play(s.animate.scale(2))
134-
self.wait()
135-
'''
136-
rendered_code = Code(code=code, tab_width=4, background="window",
137-
language="Python", font="Monospace")
138-
self.add(rendered_code)
139-
140141
"""
141142

142143
# tuples in the form (name, aliases, filetypes, mimetypes)

0 commit comments

Comments
 (0)