@@ -59,6 +59,8 @@ class NumberLine(Line):
5959 The thickness of the line.
6060 include_tip
6161 Whether to add a tip to the end of the line.
62+ include_double_sided_tip
63+ Should tips be added on both ends? Ignores value of include_tip if passed True
6264 tip_width
6365 The width of the tip.
6466 tip_height
@@ -156,6 +158,7 @@ def __init__(
156158 stroke_width : float = 2.0 ,
157159 # tip
158160 include_tip : bool = False ,
161+ include_double_sided_tip : bool = False ,
159162 tip_width : float = DEFAULT_ARROW_TIP_LENGTH ,
160163 tip_height : float = DEFAULT_ARROW_TIP_LENGTH ,
161164 tip_shape : type [ArrowTip ] | None = None ,
@@ -210,6 +213,7 @@ def __init__(
210213 self .rotation = rotation
211214 # tip
212215 self .include_tip = include_tip
216+ self .include_double_sided_tip = include_double_sided_tip
213217 self .tip_width = tip_width
214218 self .tip_height = tip_height
215219 # numbers
@@ -238,14 +242,23 @@ def __init__(
238242
239243 self .center ()
240244
241- if self .include_tip :
245+ if self .include_double_sided_tip or self . include_tip :
242246 self .add_tip (
243247 tip_length = self .tip_height ,
244248 tip_width = self .tip_width ,
245249 tip_shape = tip_shape ,
246250 )
247251 self .tip .set_stroke (self .stroke_color , self .stroke_width )
248252
253+ if self .include_double_sided_tip :
254+ self .add_tip (
255+ tip_length = self .tip_height ,
256+ tip_width = self .tip_width ,
257+ tip_shape = tip_shape ,
258+ at_start = True ,
259+ )
260+ self .start_tip .set_stroke (self .stroke_color , self .stroke_width )
261+
249262 if self .include_ticks :
250263 self .add_ticks ()
251264
@@ -335,12 +348,15 @@ def get_tick_range(self) -> np.ndarray:
335348 Returns
336349 -------
337350 np.ndarray
338- A numpy array of floats represnting values along the number line.
351+ A numpy array of floats representing values along the number line.
339352 """
340353 x_min , x_max , x_step = self .x_range
341- if not self .include_tip :
354+ if not self .include_tip and not self . include_double_sided_tip :
342355 x_max += 1e-6
343356
357+ if not self .include_double_sided_tip :
358+ x_min -= 1e-6
359+
344360 # Handle cases where min and max are both positive or both negative
345361 if x_min < x_max < 0 or x_max > x_min > 0 :
346362 tick_range = np .arange (x_min , x_max , x_step )
@@ -349,7 +365,7 @@ def get_tick_range(self) -> np.ndarray:
349365 if self .exclude_origin_tick :
350366 start_point += x_step
351367
352- x_min_segment = np .arange (start_point , np .abs (x_min ) + 1e-6 , x_step ) * - 1
368+ x_min_segment = np .arange (start_point , np .abs (x_min ), x_step ) * - 1
353369 x_max_segment = np .arange (start_point , x_max , x_step )
354370
355371 tick_range = np .unique (np .concatenate ((x_min_segment , x_max_segment )))
0 commit comments