mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Small fixes to Axes configuration
This commit is contained in:
parent
c6fc8dcf45
commit
15f03dae7b
2 changed files with 24 additions and 17 deletions
|
@ -346,15 +346,16 @@ class CoordinateSystemExample(Scene):
|
||||||
width=10,
|
width=10,
|
||||||
# Axes is made of two NumberLine mobjects. You can specify
|
# Axes is made of two NumberLine mobjects. You can specify
|
||||||
# their configuration with axis_config
|
# their configuration with axis_config
|
||||||
axis_config={
|
axis_config=dict(
|
||||||
"stroke_color": GREY_A,
|
stroke_color=GREY_A,
|
||||||
"stroke_width": 2,
|
stroke_width=2,
|
||||||
},
|
numbers_to_exclude=[0],
|
||||||
|
),
|
||||||
# Alternatively, you can specify configuration for just one
|
# Alternatively, you can specify configuration for just one
|
||||||
# of them, like this.
|
# of them, like this.
|
||||||
y_axis_config={
|
y_axis_config=dict(
|
||||||
"include_tip": False,
|
numbers_with_elongated_ticks=[-2, 2],
|
||||||
}
|
)
|
||||||
)
|
)
|
||||||
# Keyword arguments of add_coordinate_labels can be used to
|
# Keyword arguments of add_coordinate_labels can be used to
|
||||||
# configure the DecimalNumber mobjects which it creates and
|
# configure the DecimalNumber mobjects which it creates and
|
||||||
|
|
|
@ -32,7 +32,7 @@ from manimlib.utils.space_ops import normalize
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Callable, Iterable, Sequence, Type, TypeVar, Tuple
|
from typing import Callable, Iterable, Sequence, Type, TypeVar
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.constants import ManimColor, np_vector, RangeSpecifier
|
from manimlib.constants import ManimColor, np_vector, RangeSpecifier
|
||||||
|
|
||||||
|
@ -397,16 +397,15 @@ class CoordinateSystem(ABC):
|
||||||
|
|
||||||
|
|
||||||
class Axes(VGroup, CoordinateSystem):
|
class Axes(VGroup, CoordinateSystem):
|
||||||
|
default_y_axis_config: dict = dict(line_to_number_direction=LEFT)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
x_range: RangeSpecifier = DEFAULT_X_RANGE,
|
x_range: RangeSpecifier = DEFAULT_X_RANGE,
|
||||||
y_range: RangeSpecifier = DEFAULT_Y_RANGE,
|
y_range: RangeSpecifier = DEFAULT_Y_RANGE,
|
||||||
axis_config: dict = dict(
|
axis_config: dict = dict(),
|
||||||
include_tip=False,
|
|
||||||
numbers_to_exclude=[0],
|
|
||||||
),
|
|
||||||
x_axis_config: dict = dict(),
|
x_axis_config: dict = dict(),
|
||||||
y_axis_config: dict = dict(line_to_number_direction=LEFT),
|
y_axis_config: dict = dict(),
|
||||||
height: float = FRAME_HEIGHT - 2,
|
height: float = FRAME_HEIGHT - 2,
|
||||||
width: float = FRAME_WIDTH - 2,
|
width: float = FRAME_WIDTH - 2,
|
||||||
**kwargs
|
**kwargs
|
||||||
|
@ -416,12 +415,18 @@ class Axes(VGroup, CoordinateSystem):
|
||||||
|
|
||||||
self.x_axis = self.create_axis(
|
self.x_axis = self.create_axis(
|
||||||
self.x_range,
|
self.x_range,
|
||||||
axis_config=merge_dicts_recursively(axis_config, x_axis_config),
|
axis_config=merge_dicts_recursively(
|
||||||
|
axis_config, x_axis_config
|
||||||
|
),
|
||||||
length=width,
|
length=width,
|
||||||
)
|
)
|
||||||
self.y_axis = self.create_axis(
|
self.y_axis = self.create_axis(
|
||||||
self.y_range,
|
self.y_range,
|
||||||
axis_config=merge_dicts_recursively(axis_config, y_axis_config),
|
axis_config=merge_dicts_recursively(
|
||||||
|
self.default_y_axis_config,
|
||||||
|
axis_config,
|
||||||
|
y_axis_config
|
||||||
|
),
|
||||||
length=height
|
length=height
|
||||||
)
|
)
|
||||||
self.y_axis.rotate(90 * DEGREES, about_point=ORIGIN)
|
self.y_axis.rotate(90 * DEGREES, about_point=ORIGIN)
|
||||||
|
@ -435,7 +440,7 @@ class Axes(VGroup, CoordinateSystem):
|
||||||
def create_axis(
|
def create_axis(
|
||||||
self,
|
self,
|
||||||
range_terms: RangeSpecifier,
|
range_terms: RangeSpecifier,
|
||||||
axis_config: dict[str],
|
axis_config: dict,
|
||||||
length: float
|
length: float
|
||||||
) -> NumberLine:
|
) -> NumberLine:
|
||||||
axis = NumberLine(range_terms, width=length, **axis_config)
|
axis = NumberLine(range_terms, width=length, **axis_config)
|
||||||
|
@ -465,12 +470,13 @@ class Axes(VGroup, CoordinateSystem):
|
||||||
self,
|
self,
|
||||||
x_values: Iterable[float] | None = None,
|
x_values: Iterable[float] | None = None,
|
||||||
y_values: Iterable[float] | None = None,
|
y_values: Iterable[float] | None = None,
|
||||||
|
excluding: Iterable[float] = [0],
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> VGroup:
|
) -> VGroup:
|
||||||
axes = self.get_axes()
|
axes = self.get_axes()
|
||||||
self.coordinate_labels = VGroup()
|
self.coordinate_labels = VGroup()
|
||||||
for axis, values in zip(axes, [x_values, y_values]):
|
for axis, values in zip(axes, [x_values, y_values]):
|
||||||
labels = axis.add_numbers(values, **kwargs)
|
labels = axis.add_numbers(values, excluding=excluding, **kwargs)
|
||||||
self.coordinate_labels.add(labels)
|
self.coordinate_labels.add(labels)
|
||||||
return self.coordinate_labels
|
return self.coordinate_labels
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue