@@ -346,6 +346,71 @@ def axes(mark=None, options={}, **kwargs):
346
346
return axes
347
347
348
348
349
+ def grids (fig = None , value = 'solid' ):
350
+ """Sets the value of the grid_lines for the axis to the passed value.
351
+ The default value is `solid`.
352
+
353
+ Parameters
354
+ ----------
355
+ fig: Figure or None(default: None)
356
+ The figure for which the axes should be edited. If the value is None,
357
+ the current figure is used.
358
+ value: {'none', 'solid', 'dashed'}
359
+ The display of the grid_lines
360
+ """
361
+
362
+ if fig is None :
363
+ fig = current_figure ()
364
+ for a in fig .axes :
365
+ a .grid_lines = value
366
+
367
+
368
+ def hline (level , fig = None , preserve_domain = False , ** kwargs ):
369
+ """Draws a horizontal line at the given level.
370
+
371
+ Parameters
372
+ ----------
373
+ level: float
374
+ The level at which to draw the horizontal line.
375
+ fig: Figure or None
376
+ The figure to which the horizontal line is to be added.
377
+ If the value is None, the current figure is used.
378
+ preserve_domain: boolean (default: False)
379
+ If true, the line does not affect the domain of the 'y' scale.
380
+ """
381
+ default_colors = kwargs .pop ('colors' , ['dodgerblue' ])
382
+ default_width = kwargs .pop ('stroke_width' , 1 )
383
+ if fig is None :
384
+ fig = current_figure ()
385
+ sc_x = fig .scale_x
386
+ plot ([0. , 1. ], [level , level ], scales = {'x' : sc_x }, preserve_domain = {'x' : True ,
387
+ 'y' : preserve_domain }, axes = False , colors = default_colors ,
388
+ stroke_width = default_width , update_context = False )
389
+
390
+
391
+ def vline (level , fig = None , preserve_domain = False , ** kwargs ):
392
+ """Draws a vertical line at the given level.
393
+
394
+ Parameters
395
+ ----------
396
+ level: float
397
+ The level at which to draw the vertical line.
398
+ fig: Figure or None
399
+ The figure to which the vertical line is to be added.
400
+ If the value is None, the current figure is used.
401
+ preserve_domain: boolean (default: False)
402
+ If true, the line does not affect the domain of the 'x' scale.
403
+ """
404
+ default_colors = kwargs .pop ('colors' , ['dodgerblue' ])
405
+ default_width = kwargs .pop ('stroke_width' , 1 )
406
+ if fig is None :
407
+ fig = current_figure ()
408
+ sc_y = fig .scale_y
409
+ plot ([level , level ], [0. , 1. ], scales = {'y' : sc_y }, preserve_domain = {'x' : preserve_domain ,
410
+ 'y' : True }, axes = False , colors = default_colors ,
411
+ stroke_width = default_width , update_context = False )
412
+
413
+
349
414
def _draw_mark (mark_type , options = {}, axes_options = {}, ** kwargs ):
350
415
"""Draw the mark of specified mark type.
351
416
@@ -364,6 +429,7 @@ def _draw_mark(mark_type, options={}, axes_options={}, **kwargs):
364
429
"""
365
430
fig = kwargs .pop ('figure' , current_figure ())
366
431
scales = kwargs .pop ('scales' , {})
432
+ update_context = kwargs .pop ('update_context' , True )
367
433
368
434
# Going through the list of data attributes
369
435
for name in mark_type .class_trait_names (scaled = True ):
@@ -375,7 +441,8 @@ def _draw_mark(mark_type, options={}, axes_options={}, **kwargs):
375
441
# create a scale for this.
376
442
continue
377
443
elif name in scales :
378
- _context ['scales' ][dimension ] = scales [name ]
444
+ if update_context :
445
+ _context ['scales' ][dimension ] = scales [name ]
379
446
# Scale has to be fetched from the conext or created as it has not
380
447
# been passed.
381
448
elif dimension not in _context ['scales' ]:
@@ -394,7 +461,8 @@ def _draw_mark(mark_type, options={}, axes_options={}, **kwargs):
394
461
# scale type.
395
462
scales [name ] = compat_scale_types [0 ](** options .get (name , {}))
396
463
# Adding the scale to the conext scales
397
- _context ['scales' ][dimension ] = scales [name ]
464
+ if update_context :
465
+ _context ['scales' ][dimension ] = scales [name ]
398
466
else :
399
467
scales [name ] = _context ['scales' ][dimension ]
400
468
@@ -850,8 +918,15 @@ def current_figure():
850
918
851
919
852
920
def get_context ():
853
- """Used for debug only. Return the current global context dictionary."""
854
- return _context
921
+ """Used for debug only. Return a copy of the current global context dictionary."""
922
+ return {k : v for k , v in _context .items ()}
923
+
924
+
925
+ def set_context (context ):
926
+ """Sets the current global context dictionary. All the attributes to be set
927
+ should be set. Otherwise, it will result in unpredictable behavior."""
928
+ global _context
929
+ _context = {k : v for k , v in context .items ()}
855
930
856
931
857
932
def _fetch_axis (fig , dimension , scale ):
0 commit comments