Skip to content

Commit

Permalink
Fix bug with common range array used for all coordinate systems
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Aug 19, 2021
1 parent d50717a commit 56df154
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions manimlib/mobject/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class CoordinateSystem():
"""
CONFIG = {
"dimension": 2,
"x_range": np.array([-8.0, 8.0, 1.0]),
"y_range": np.array([-4.0, 4.0, 1.0]),
"default_x_range": [-8.0, 8.0, 1.0],
"default_y_range": [-4.0, 4.0, 1.0],
"width": None,
"height": None,
"num_sampled_graph_points_per_tick": 20,
Expand Down Expand Up @@ -284,8 +284,10 @@ def __init__(self,
**kwargs):
super().__init__(**kwargs)
if x_range is not None:
self.x_range = np.array(self.default_x_range)
self.x_range[:len(x_range)] = x_range
if y_range is not None:
self.y_range = np.array(self.default_y_range)
self.y_range[:len(y_range)] = y_range

self.x_axis = self.create_axis(
Expand Down Expand Up @@ -501,15 +503,15 @@ def point_to_number(self, point):
def p2n(self, point):
return self.point_to_number(point)

def get_default_coordinate_values(self):
def get_default_coordinate_values(self, skip_first=True):
x_numbers = self.get_x_axis().get_tick_range()[1:]
y_numbers = self.get_y_axis().get_tick_range()[1:]
y_numbers = [complex(0, y) for y in y_numbers if y != 0]
return [*x_numbers, *y_numbers]

def add_coordinate_labels(self, numbers=None, **kwargs):
def add_coordinate_labels(self, numbers=None, skip_first=True, **kwargs):
if numbers is None:
numbers = self.get_default_coordinate_values()
numbers = self.get_default_coordinate_values(skip_first)

self.coordinate_labels = VGroup()
for number in numbers:
Expand All @@ -522,6 +524,9 @@ def add_coordinate_labels(self, numbers=None, **kwargs):
axis = self.get_x_axis()
value = z.real
number_mob = axis.get_number_mobject(value, **kwargs)
# For i and -i, remove the "1"
if abs(z.imag) == 1:
number_mob.remove(number_mob[0])
self.coordinate_labels.add(number_mob)
self.add(self.coordinate_labels)
return self

0 comments on commit 56df154

Please sign in to comment.