1111
1212from bokeh .core .enums import LegendLocation
1313from bokeh .io import show
14- from bokeh .models import (ColumnDataSource , DataRange1d , Legend , Line , LinearAxis ,
15- PanTool , Plot , SaveTool , Scatter , WheelZoomTool )
14+ from bokeh .models import (ColumnDataSource , DataRange1d , Legend ,
15+ Line , LinearAxis , Plot , Scatter )
1616
1717x = linspace (- 2 * pi , 2 * pi , 400 )
1818y = sin (x )
3939circle = Scatter (x = "x" , y = "y2" , size = 6 , line_color = "red" , fill_color = "orange" , fill_alpha = 0.6 )
4040circle = plot .add_glyph (source , circle )
4141
42- pan = PanTool ()
43- wheel_zoom = WheelZoomTool ()
44- preview_save = SaveTool ()
45-
46- plot .add_tools (pan , wheel_zoom , preview_save )
47-
4842# Add axes (Note it's important to add these before adding legends in side panels)
4943plot .add_layout (LinearAxis (), "below" )
5044plot .add_layout (LinearAxis (), "left" )
5145plot .add_layout (LinearAxis (), "right" )
5246
47+
5348def add_legend (location , orientation , side , background_fill_color = "#FFFFFF" ):
5449 legend = Legend (
5550 items = [("line" , [line ]), ("circle" , [circle ])],
@@ -61,14 +56,15 @@ def add_legend(location, orientation, side, background_fill_color="#FFFFFF"):
6156 )
6257 plot .add_layout (legend , side )
6358
59+
6460# Add legends in names positions e.g. "top_right", "top_left" (see plot for all)
6561for location in LegendLocation :
6662 # redundant positions get a different background color and a vertical orientation to show ambiguity
6763 if "_" not in location :
6864 background_fill_color = "#999999"
6965 orientation = "vertical"
7066 else :
71- background_fill_color = "#CCCCCC"
67+ background_fill_color = "#CCCCCC"
7268 orientation = "horizontal"
7369 add_legend (location , orientation , "center" , background_fill_color = background_fill_color )
7470
0 commit comments