#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Models for representing top-level plot objects.'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromcontextlibimportcontextmanagerfromtypingimport(Any,Generator,Literal,overload,)# External importsimportxyzservices# Bokeh importsfrom..core.enumsimport(Location,OutputBackend,Place,PlaceType,ResetPolicy,)from..core.propertiesimport(Bool,Dict,Either,Enum,Float,Include,Instance,InstanceDefault,Int,List,Null,Nullable,Override,Readonly,String,Struct,Tuple,)from..core.property.structimportOptionalfrom..core.property_mixinsimportScalarFillProps,ScalarLinePropsfrom..core.queryimportfindfrom..core.validationimporterror,warningfrom..core.validation.errorsimport(BAD_EXTRA_RANGE_NAME,INCOMPATIBLE_SCALE_AND_RANGE,REPEATED_LAYOUT_CHILD,REQUIRED_RANGE,REQUIRED_SCALE,)from..core.validation.warningsimportMISSING_RENDERERSfrom..modelimportModelfrom..util.stringsimportnice_joinfrom..util.warningsimportwarnfrom.annotationsimportAnnotation,Legend,Titlefrom.axesimportAxisfrom.domimportHTMLfrom.glyphsimportGlyphfrom.gridsimportGridfrom.layoutsimportGridCommon,LayoutDOMfrom.rangesimport(DataRange1d,FactorRange,Range,Range1d,)from.renderersimportGlyphRenderer,Renderer,TileRendererfrom.scalesimport(CategoricalScale,LinearScale,LogScale,Scale,)from.sourcesimportColumnarDataSource,ColumnDataSource,DataSourcefrom.tilesimportTileSource,WMTSTileSourcefrom.toolsimportHoverTool,Tool,Toolbar#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('GridPlot','Plot',)defLRTB(type:Any)->Struct:returnStruct(left=type,right=type,top=type,bottom=type)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classPlot(LayoutDOM):''' Model representing a plot, containing glyphs, guides, annotations. '''# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)
[docs]defselect(self,*args,**kwargs):''' Query this object and all of its references for objects that match the given selector. There are a few different ways to call the ``select`` method. The most general is to supply a JSON-like query dictionary as the single argument or as keyword arguments: Args: selector (JSON-like) : some sample text Keyword Arguments: kwargs : query dict key/values as keyword arguments Additionally, for compatibility with ``Model.select``, a selector dict may be passed as ``selector`` keyword argument, in which case the value of ``kwargs['selector']`` is used for the query. For convenience, queries on just names can be made by supplying the ``name`` string as the single parameter: Args: name (str) : the name to query on Also queries on just type can be made simply by supplying the ``Model`` subclass as the single parameter: Args: type (Model) : the type to query on Returns: seq[Model] Examples: .. code-block:: python # These three are equivalent p.select(selector={"type": HoverTool}) p.select({"type": HoverTool}) p.select(HoverTool) # These two are also equivalent p.select({"name": "mycircle"}) p.select("mycircle") # Keyword arguments can be supplied in place of selector dict p.select({"name": "foo", "type": HoverTool}) p.select(name="foo", type=HoverTool) '''selector=_select_helper(args,kwargs)# Want to pass selector that is a dictionaryreturn_list_attr_splat(find(self.references(),selector))
[docs]defrow(self,row,gridplot):''' Return whether this plot is in a given row of a GridPlot. Args: row (int) : index of the row to test gridplot (GridPlot) : the GridPlot to check Returns: bool '''returnselfingridplot.row(row)
[docs]defcolumn(self,col,gridplot):''' Return whether this plot is in a given column of a GridPlot. Args: col (int) : index of the column to test gridplot (GridPlot) : the GridPlot to check Returns: bool '''returnselfingridplot.column(col)
def_axis(self,*sides):objs=[]forsinsides:objs.extend(getattr(self,s,[]))axis=[objforobjinobjsifisinstance(obj,Axis)]return_list_attr_splat(axis)@propertydefxaxis(self):''' Splattable list of :class:`~bokeh.models.axes.Axis` objects for the x dimension. '''returnself._axis("above","below")@propertydefyaxis(self):''' Splattable list of :class:`~bokeh.models.axes.Axis` objects for the y dimension. '''returnself._axis("left","right")@propertydefaxis(self):''' Splattable list of :class:`~bokeh.models.axes.Axis` objects. '''return_list_attr_splat(self.xaxis+self.yaxis)@propertydeflegend(self):''' Splattable list of |Legend| objects. '''panels=self.above+self.below+self.left+self.right+self.centerlegends=[objforobjinpanelsifisinstance(obj,Legend)]return_legend_attr_splat(legends)@propertydefhover(self):''' Splattable list of :class:`~bokeh.models.tools.HoverTool` objects. '''hovers=[objforobjinself.toolsifisinstance(obj,HoverTool)]return_list_attr_splat(hovers)def_grid(self,dimension:Literal[0,1]):grid=[objforobjinself.centerifisinstance(obj,Grid)andobj.dimension==dimension]return_list_attr_splat(grid)@propertydefxgrid(self):''' Splattable list of :class:`~bokeh.models.grids.Grid` objects for the x dimension. '''returnself._grid(0)@propertydefygrid(self):''' Splattable list of :class:`~bokeh.models.grids.Grid` objects for the y dimension. '''returnself._grid(1)@propertydefgrid(self):''' Splattable list of :class:`~bokeh.models.grids.Grid` objects. '''return_list_attr_splat(self.xgrid+self.ygrid)@propertydeftools(self)->list[Tool]:returnself.toolbar.tools@tools.setterdeftools(self,tools:list[Tool]):self.toolbar.tools=tools
[docs]defadd_layout(self,obj:Renderer,place:PlaceType="center")->None:''' Adds an object to the plot in a specified place. Args: obj (Renderer) : the object to add to the Plot place (str, optional) : where to add the object (default: 'center') Valid places are: 'left', 'right', 'above', 'below', 'center'. Returns: None '''ifplacenotinPlace:raiseValueError(f"Invalid place '{place}' specified. Valid place values are: {nice_join(Place)}",)getattr(self,place).append(obj)
[docs]defadd_tools(self,*tools:Tool|str)->None:''' Adds tools to the plot. Args: *tools (Tool) : the tools to add to the Plot Returns: None '''fortoolintools:ifisinstance(tool,str):tool_obj=Tool.from_string(tool)elifisinstance(tool,Tool):tool_obj=toolelse:raiseValueError(f"expected a string or Tool instance, got {tool!r}")self.toolbar.tools.append(tool_obj)
[docs]defremove_tools(self,*tools:Tool)->None:''' Removes tools from the plot. Args: *tools (Tool) : the tools to remove from the Plot Returns: None '''fortoolintools:ifnotisinstance(tool,Tool):raiseValueError("All arguments to remove_tool must be Tool subclasses.")eliftoolnotinself.toolbar.tools:raiseValueError(f"Invalid tool {tool} specified. Available tools are {nice_join(self.toolbar.tools)}")self.toolbar.tools.remove(tool)
[docs]defadd_glyph(self,source_or_glyph:Glyph|ColumnarDataSource,glyph:Glyph|None=None,**kwargs:Any)->GlyphRenderer:''' Adds a glyph to the plot with associated data sources and ranges. This function will take care of creating and configuring a Glyph object, and then add it to the plot's list of renderers. Args: source (DataSource) : a data source for the glyphs to all use glyph (Glyph) : the glyph to add to the Plot Keyword Arguments: Any additional keyword arguments are passed on as-is to the Glyph initializer. Returns: GlyphRenderer '''ifisinstance(source_or_glyph,ColumnarDataSource):source=source_or_glyphelse:source,glyph=ColumnDataSource(),source_or_glyphifnotisinstance(source,DataSource):raiseValueError("'source' argument to add_glyph() must be DataSource subclass")ifnotisinstance(glyph,Glyph):raiseValueError("'glyph' argument to add_glyph() must be Glyph subclass")g=GlyphRenderer(data_source=source,glyph=glyph,**kwargs)self.renderers.append(g)returng
[docs]defadd_tile(self,tile_source:TileSource|xyzservices.TileProvider|str,retina:bool=False,**kwargs:Any)->TileRenderer:''' Adds new ``TileRenderer`` into ``Plot.renderers`` Args: tile_source (TileSource, xyzservices.TileProvider, str) : A tile source instance which contain tileset configuration retina (bool) : Whether to use retina version of tiles (if available) Keyword Arguments: Additional keyword arguments are passed on as-is to the tile renderer Returns: TileRenderer : TileRenderer '''ifnotisinstance(tile_source,TileSource):ifisinstance(tile_source,xyzservices.TileProvider):selected_provider=tile_source# allow the same string input you can now pass to get_providerelifisinstance(tile_source,str):# Mapping of custom keys to those used in xyzservicestile_source=tile_source.lower()iftile_source=="esri_imagery":tile_source="esri_worldimagery"iftile_source=="osm":tile_source="openstreetmap_mapnik"iftile_source.startswith("stamen"):tile_source=f"stadia.{tile_source}"if"retina"intile_source:tile_source=tile_source.replace("retina","")retina=Trueselected_provider=xyzservices.providers.query_name(tile_source)scale_factor="@2x"ifretinaelseNonetile_source=WMTSTileSource(url=selected_provider.build_url(scale_factor=scale_factor),attribution=selected_provider.html_attribution,min_zoom=selected_provider.get("min_zoom",0),max_zoom=selected_provider.get("max_zoom",30),)tile_renderer=TileRenderer(tile_source=tile_source,**kwargs)self.renderers.append(tile_renderer)returntile_renderer
[docs]@contextmanagerdefhold(self,*,render:bool)->Generator[None,None,None]:''' Takes care of turning a property on and off within a scope. Args: render (bool) : Turns the property hold_render on and off. '''ifrender:self.hold_render=Trueyieldself.hold_render=False
@error(REQUIRED_RANGE)def_check_required_range(self)->str|None:missing:list[str]=[]ifnotself.x_range:missing.append('x_range')ifnotself.y_range:missing.append('y_range')ifmissing:return", ".join(missing)+f" [{self}]"@error(REQUIRED_SCALE)def_check_required_scale(self)->str|None:missing:list[str]=[]ifnotself.x_scale:missing.append('x_scale')ifnotself.y_scale:missing.append('y_scale')ifmissing:return", ".join(missing)+f" [{self}]"@error(INCOMPATIBLE_SCALE_AND_RANGE)def_check_compatible_scale_and_ranges(self)->str|None:incompatible:list[str]=[]x_ranges=list(self.extra_x_ranges.values())ifself.x_range:x_ranges.append(self.x_range)y_ranges=list(self.extra_y_ranges.values())ifself.y_range:y_ranges.append(self.y_range)ifself.x_scaleisnotNone:forrnginx_ranges:ifisinstance(rng,DataRange1d|Range1d)andnotisinstance(self.x_scale,LinearScale|LogScale):incompatible.append(f"incompatibility on x-dimension: {rng}, {self.x_scale}")elifisinstance(rng,FactorRange)andnotisinstance(self.x_scale,CategoricalScale):incompatible.append(f"incompatibility on x-dimension: {rng}, {self.x_scale}")ifself.y_scaleisnotNone:forrnginy_ranges:ifisinstance(rng,DataRange1d|Range1d)andnotisinstance(self.y_scale,LinearScale|LogScale):incompatible.append(f"incompatibility on y-dimension: {rng}, {self.y_scale}")elifisinstance(rng,FactorRange)andnotisinstance(self.y_scale,CategoricalScale):incompatible.append(f"incompatibility on y-dimension: {rng}, {self.y_scale}")ifincompatible:return", ".join(incompatible)+f" [{self}]"@warning(MISSING_RENDERERS)def_check_missing_renderers(self)->str|None:iflen(self.renderers)==0andlen([xforxinself.centerifisinstance(x,Annotation)])==0:returnstr(self)@error(BAD_EXTRA_RANGE_NAME)def_check_bad_extra_range_name(self)->str|None:msg:str=""valid={f'{axis}_name':{'default',*getattr(self,f"extra_{axis}s")}foraxisin("x_range","y_range")}forplacein[*list(Place),'renderers']:forrefingetattr(self,place):bad=', '.join(f"{axis}='{getattr(ref,axis)}'"foraxis,keysinvalid.items()ifgetattr(ref,axis,'default')notinkeys)ifbad:msg+=(", "ifmsgelse"")+f"{bad} [{ref}]"ifmsg:returnmsgx_range=Instance(Range,default=InstanceDefault(DataRange1d),help=""" The (default) data range of the horizontal dimension of the plot. """)y_range=Instance(Range,default=InstanceDefault(DataRange1d),help=""" The (default) data range of the vertical dimension of the plot. """)x_scale=Instance(Scale,default=InstanceDefault(LinearScale),help=""" What kind of scale to use to convert x-coordinates in data space into x-coordinates in screen space. """)y_scale=Instance(Scale,default=InstanceDefault(LinearScale),help=""" What kind of scale to use to convert y-coordinates in data space into y-coordinates in screen space. """)extra_x_ranges=Dict(String,Instance(Range),help=""" Additional named ranges to make available for mapping x-coordinates. This is useful for adding additional axes. """)extra_y_ranges=Dict(String,Instance(Range),help=""" Additional named ranges to make available for mapping y-coordinates. This is useful for adding additional axes. """)extra_x_scales=Dict(String,Instance(Scale),help=""" Additional named scales to make available for mapping x-coordinates. This is useful for adding additional axes. .. note:: This feature is experimental and may change in the short term. """)extra_y_scales=Dict(String,Instance(Scale),help=""" Additional named scales to make available for mapping y-coordinates. This is useful for adding additional axes. .. note:: This feature is experimental and may change in the short term. """)hidpi=Bool(default=True,help=""" Whether to use HiDPI mode when available. """)title=Either(Null,Instance(Title),default=InstanceDefault(Title,text=""),help=""" A title for the plot. Can be a text string or a Title annotation. """).accepts(String,lambdatext:Title(text=text))title_location=Nullable(Enum(Location),default="above",help=""" Where the title will be located. Titles on the left or right side will be rotated. """)outline_props=Include(ScalarLineProps,prefix="outline",help=""" The {prop} for the plot border outline. """)outline_line_color=Override(default="#e5e5e5")renderers=List(Instance(Renderer),help=""" A list of all glyph renderers for this plot. This property can be manipulated by hand, but the ``add_glyph`` is recommended to help make sure all necessary setup is performed. """)toolbar=Instance(Toolbar,default=InstanceDefault(Toolbar),help=""" The toolbar associated with this plot which holds all the tools. It is automatically created with the plot if necessary. """)toolbar_location=Nullable(Enum(Location),default="right",help=""" Where the toolbar will be located. If set to None, no toolbar will be attached to the plot. """)toolbar_sticky=Bool(default=True,help=""" Stick the toolbar to the edge of the plot. Default: True. If False, the toolbar will be outside of the axes, titles etc. """)toolbar_inner=Bool(default=False,help=""" Locate the toolbar inside the frame. Setting this property to ``True`` makes most sense with auto-hidden toolbars. """)left=List(Instance(Renderer),help=""" A list of renderers to occupy the area to the left of the plot. """)right=List(Instance(Renderer),help=""" A list of renderers to occupy the area to the right of the plot. """)above=List(Instance(Renderer),help=""" A list of renderers to occupy the area above of the plot. """)below=List(Instance(Renderer),help=""" A list of renderers to occupy the area below of the plot. """)center=List(Instance(Renderer),help=""" A list of renderers to occupy the center area (frame) of the plot. """)width:int|None=Override(default=600)height:int|None=Override(default=600)frame_width=Nullable(Int,help=""" The width of a plot frame or the inner width of a plot, excluding any axes, titles, border padding, etc. """)frame_height=Nullable(Int,help=""" The height of a plot frame or the inner height of a plot, excluding any axes, titles, border padding, etc. """)frame_align=Either(Bool,LRTB(Optional(Bool)),default=True,help=""" Allows to specify which frame edges to align in multiple-plot layouts. The default is to align all edges, but users can opt-out from alignment of each individual edge or all edges. Note also that other properties may disable alignment of certain edges, especially when using fixed frame size (``frame_width`` and ``frame_height`` properties). """)inner_width=Readonly(Int,help=""" This is the exact width of the plotting canvas, i.e. the width of the actual plot, without toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook). .. note:: This is an experimental feature and the API may change in near future. """)inner_height=Readonly(Int,help=""" This is the exact height of the plotting canvas, i.e. the height of the actual plot, without toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook). .. note:: This is an experimental feature and the API may change in near future. """)outer_width=Readonly(Int,help=""" This is the exact width of the layout, i.e. the height of the actual plot, with toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook). .. note:: This is an experimental feature and the API may change in near future. """)outer_height=Readonly(Int,help=""" This is the exact height of the layout, i.e. the height of the actual plot, with toolbars etc. Note this is computed in a web browser, so this property will work only in backends capable of bidirectional communication (server, notebook). .. note:: This is an experimental feature and the API may change in near future. """)background_props=Include(ScalarFillProps,prefix="background",help=""" The {prop} for the plot background style. """)background_fill_color=Override(default='#ffffff')border_props=Include(ScalarFillProps,prefix="border",help=""" The {prop} for the plot border style. """)border_fill_color=Override(default='#ffffff')min_border_top=Nullable(Int,help=""" Minimum size in pixels of the padding region above the top of the central plot region. .. note:: This is a *minimum*. The padding region may expand as needed to accommodate titles or axes, etc. """)min_border_bottom=Nullable(Int,help=""" Minimum size in pixels of the padding region below the bottom of the central plot region. .. note:: This is a *minimum*. The padding region may expand as needed to accommodate titles or axes, etc. """)min_border_left=Nullable(Int,help=""" Minimum size in pixels of the padding region to the left of the central plot region. .. note:: This is a *minimum*. The padding region may expand as needed to accommodate titles or axes, etc. """)min_border_right=Nullable(Int,help=""" Minimum size in pixels of the padding region to the right of the central plot region. .. note:: This is a *minimum*. The padding region may expand as needed to accommodate titles or axes, etc. """)min_border=Nullable(Int,default=5,help=""" A convenience property to set all all the ``min_border_X`` properties to the same value. If an individual border property is explicitly set, it will override ``min_border``. """)lod_factor=Int(10,help=""" Decimation factor to use when applying level-of-detail decimation. """)lod_threshold=Nullable(Int,default=2000,help=""" A number of data points, above which level-of-detail downsampling may be performed by glyph renderers. Set to ``None`` to disable any level-of-detail downsampling. """)lod_interval=Int(300,help=""" Interval (in ms) during which an interactive tool event will enable level-of-detail downsampling. """)lod_timeout=Int(500,help=""" Timeout (in ms) for checking whether interactive tool events are still occurring. Once level-of-detail mode is enabled, a check is made every ``lod_timeout`` ms. If no interactive tool events have happened, level-of-detail mode is disabled. """)output_backend=Enum(OutputBackend,default="canvas",help=""" Specify the output backend for the plot area. Default is HTML5 Canvas. .. note:: When set to ``webgl``, glyphs without a WebGL rendering implementation will fall back to rendering onto 2D canvas. """)match_aspect=Bool(default=False,help=""" Specify the aspect ratio behavior of the plot. Aspect ratio is defined as the ratio of width over height. This property controls whether Bokeh should attempt to match the (width/height) of *data space* to the (width/height) in pixels of *screen space*. Default is ``False`` which indicates that the *data* aspect ratio and the *screen* aspect ratio vary independently. ``True`` indicates that the plot aspect ratio of the axes will match the aspect ratio of the pixel extent the axes. The end result is that a 1x1 area in data space is a square in pixels, and conversely that a 1x1 pixel is a square in data units. .. note:: This setting only takes effect when there are two dataranges. This setting only sets the initial plot draw and subsequent resets. It is possible for tools (single axis zoom, unconstrained box zoom) to change the aspect ratio. .. warning:: This setting is incompatible with linking dataranges across multiple plots. Doing so may result in undefined behavior. """)aspect_scale=Float(default=1,help=""" A value to be given for increased aspect ratio control. This value is added multiplicatively to the calculated value required for ``match_aspect``. ``aspect_scale`` is defined as the ratio of width over height of the figure. For example, a plot with ``aspect_scale`` value of 2 will result in a square in *data units* to be drawn on the screen as a rectangle with a pixel width twice as long as its pixel height. .. note:: This setting only takes effect if ``match_aspect`` is set to ``True``. """)reset_policy=Enum(ResetPolicy,default="standard",help=""" How a plot should respond to being reset. By default, the standard actions are to clear any tool state history, return plot ranges to their original values, undo all selections, and emit a ``Reset`` event. If customization is desired, this property may be set to ``"event_only"``, which will suppress all of the actions except the Reset event. """)hold_render=Bool(default=False,help=""" When set to True all requests to repaint the plot will be hold off. This is useful when periodically updating many glyphs. For example, let's assume we have 10 lines on a plot, each with its own datasource. We stream to all of them every second in a for loop like so: .. code:: python for line in lines: line.stream(new_points()) The problem with this code is that every stream triggers a re-rendering of the plot. Even tough repainting only on the last stream would produce almost identical visual effect. Especially for lines with many points this becomes computationally expensive and can freeze your browser. Using a convenience method `hold`, we can control when rendering is initiated like so: .. code:: python with plot.hold(render=True): for line in lines: line.stream(new_points()) In this case we render newly appended points only after the last stream. """)attribution=List(Either(Instance(HTML),String),default=[],help=""" Allows to acknowledge or give credit to data, tile, etc. providers. This can be in either HTML or plain text forms. Renderers, like tile renderers, can provide additional attributions which will be added after attributions provided here. .. note:: This feature is experimental and may change in the short term. """)
[docs]classGridPlot(LayoutDOM,GridCommon):""" Collection of plots and other layoutables on arranged on a rectangular grid. """# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)toolbar=Instance(Toolbar,default=InstanceDefault(Toolbar),help=""" The toolbar associated with this grid plot, which holds all the tools. It is automatically created with the plot if necessary. """)toolbar_location=Nullable(Enum(Location),default="above",help=""" Indicates where the layout the toolbar will be located. If set to None, no toolbar will be attached to the grid plot. """)children=List(Either(Tuple(Instance(LayoutDOM),Int,Int),Tuple(Instance(LayoutDOM),Int,Int,Int,Int)),default=[],help=""" A list of subplots with their associated position in the grid, row and column index and optional row and column spans (the default span is 1). """)@error(REPEATED_LAYOUT_CHILD)def_check_repeated_layout_children(self):children=[child[0]forchildinself.children]iflen(children)!=len(set(children)):returnstr(self)
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------def_check_conflicting_kwargs(a1,a2,kwargs):ifa1inkwargsanda2inkwargs:raiseValueError(f"Conflicting properties set on plot: {a1!r} and {a2!r}")class_list_attr_splat(list):def__setattr__(self,attr,value):forxinself:setattr(x,attr,value)def__getattribute__(self,attr):ifattrindir(list):returnlist.__getattribute__(self,attr)iflen(self)==0:raiseAttributeError(f"Trying to access {attr!r} attribute on an empty 'splattable' list")iflen(self)==1:returngetattr(self[0],attr)try:return_list_attr_splat([getattr(x,attr)forxinself])exceptException:raiseAttributeError(f"Trying to access {attr!r} attribute on a 'splattable' list, but list items have no {attr!r} attribute")def__dir__(self):iflen({type(x)forxinself})==1:returndir(self[0])else:returndir(self)_LEGEND_EMPTY_WARNING="""You are attempting to set `plot.legend.%s` on a plot that has zero legends added, this will have no effect.Before legend properties can be set, you must add a Legend explicitly, or call a glyph method with a legend parameter set."""class_legend_attr_splat(_list_attr_splat):def__setattr__(self,attr,value):ifnotlen(self):warn(_LEGEND_EMPTY_WARNING%attr)returnsuper().__setattr__(attr,value)def_select_helper(args,kwargs):""" Allow flexible selector syntax. Returns: dict """iflen(args)>1:raiseTypeError("select accepts at most ONE positional argument.")iflen(args)>0andlen(kwargs)>0:raiseTypeError("select accepts EITHER a positional argument, OR keyword arguments (not both).")iflen(args)==0andlen(kwargs)==0:raiseTypeError("select requires EITHER a positional argument, OR keyword arguments.")ifargs:arg=args[0]ifisinstance(arg,dict):selector=argelifisinstance(arg,str):selector=dict(name=arg)elifisinstance(arg,type)andissubclass(arg,Model):selector={"type":arg}else:raiseTypeError("selector must be a dictionary, string or plot object.")elif'selector'inkwargs:iflen(kwargs)==1:selector=kwargs['selector']else:raiseTypeError("when passing 'selector' keyword arg, not other keyword args may be present")else:selector=kwargsreturnselector#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------