Skip to content

Commit 7027f0a

Browse files
roopeshorbehackljsonvillanueva
authored
Improve Axes: rotate labels of y-axis (#718)
* Rotating the numbers in y axis I don't know why people haven't fixed this issue. In Axes, the y axis will be rotated 90deg. But the numbers are also rotated. to fix it i rotated numbers in y axis -90deg * Update coordinate_systems.py * Added missing 'self' * optimized code * Added code for rotating numbers in y-axis * Update graph_scene.py * Update graph_scene.py * removed code for testing * Update graph_scene.py * propose alternative approach for rotating labels of axes * unify behavior of Axes and GraphScene: add labels in Axes only after rotation * Update number_line.py Updated file to property access fix on master Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: Jason Villanueva <[email protected]>
1 parent 0de873c commit 7027f0a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

manim/mobject/coordinate_systems.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
self,
135135
axis_config=None,
136136
x_axis_config=None,
137-
y_axis_config={"label_direction": LEFT},
137+
y_axis_config=None,
138138
center_point=ORIGIN,
139139
**kwargs
140140
):
@@ -144,6 +144,8 @@ def __init__(
144144
"include_tip": True,
145145
"exclude_zero_from_default_numbers": True,
146146
}
147+
if y_axis_config is None:
148+
y_axis_config = {"label_direction": LEFT, "rotation": 90 * DEGREES}
147149
self.axis_config = axis_config
148150
if x_axis_config is None:
149151
x_axis_config = {}
@@ -154,7 +156,6 @@ def __init__(
154156
VGroup.__init__(self, **kwargs)
155157
self.x_axis = self.create_axis(self.x_min, self.x_max, self.x_axis_config)
156158
self.y_axis = self.create_axis(self.y_min, self.y_max, self.y_axis_config)
157-
self.y_axis.rotate(90 * DEGREES, about_point=ORIGIN)
158159
# Add as a separate group in case various other
159160
# mobjects are added to self, as for example in
160161
# NumberPlane below

manim/mobject/number_line.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(
2424
color=LIGHT_GREY,
2525
unit_size=1,
2626
width=None,
27+
rotation=0,
2728
include_ticks=True,
2829
tick_size=0.1,
2930
tick_frequency=1,
@@ -53,6 +54,7 @@ def __init__(
5354
self.unit_size = unit_size
5455
self.include_ticks = include_ticks
5556
self.tick_size = tick_size
57+
self.rotation = rotation
5658
self.tick_frequency = tick_frequency
5759
self.leftmost_tick = leftmost_tick
5860
self.numbers_with_elongated_ticks = numbers_with_elongated_ticks
@@ -92,6 +94,7 @@ def __init__(
9294
self.add_tip()
9395
if self.include_ticks:
9496
self.add_tick_marks()
97+
self.rotate(self.rotation)
9598
if self.include_numbers:
9699
self.add_numbers()
97100

@@ -186,7 +189,12 @@ def default_numbers_to_display(self):
186189
return numbers
187190

188191
def get_number_mobject(
189-
self, number, number_config=None, scale_val=None, direction=None, buff=None
192+
self,
193+
number,
194+
number_config=None,
195+
scale_val=None,
196+
direction=None,
197+
buff=None,
190198
):
191199
number_config = merge_dicts_recursively(
192200
self.decimal_number_config,

manim/scene/graph_scene.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def __init__(
104104
y_axis_visibility=True, # show or hide the y axis
105105
x_label_position=UP + RIGHT, # where to place the label of the x axis
106106
y_label_position=UP + RIGHT, # where to place the label of the y axis
107-
x_axis_config={},
108-
y_axis_config={},
107+
x_axis_config=None,
108+
y_axis_config=None,
109109
**kwargs,
110110
):
111111
self.x_min = x_min
@@ -135,8 +135,8 @@ def __init__(
135135
self.y_axis_visibility = y_axis_visibility
136136
self.x_label_position = x_label_position
137137
self.y_label_position = y_label_position
138-
self.x_axis_config = x_axis_config
139-
self.y_axis_config = y_axis_config
138+
self.x_axis_config = {} if x_axis_config is None else x_axis_config
139+
self.y_axis_config = {} if y_axis_config is None else y_axis_config
140140
super().__init__(**kwargs)
141141

142142
def setup(self):
@@ -232,6 +232,7 @@ def setup_axes(self, animate=False):
232232
)
233233
y_axis.shift(self.graph_origin - y_shift)
234234
y_axis.rotate(np.pi / 2, about_point=self.graph_origin)
235+
235236
if len(self.y_labeled_nums) > 0:
236237
if self.exclude_zero_label:
237238
self.y_labeled_nums = [y for y in self.y_labeled_nums if y != 0]

0 commit comments

Comments
 (0)