Search code examples
pythonbokeh

bokeh background fill color


Below is a screenshot of the plot that I have. The plot on the left is the one I generate, and the plot on the right is the same plot that I have panned to illustrate where the background_fill_color is getting applied.

The color labelled as (x) is what I'm looking to apply in the area labelled (y).

Added the exact code below now

    TOOLTIPS = [("(x,y)", "($x, $y)")]
    p = figure(tools="pan,box_zoom,reset,save",
               title=TITLE,x_range=x, 
               y_range=(<<my_y0_range_1>>,<<my_y0_range_2>>), 
               x_axis_label='time',y_axis_label='index',
               plot_width=150, plot_height=100,toolbar_location="below",
               tooltips=TOOLTIPS)
    p.background_fill_color = <<mycolor>>
    p.line(x, y0, legend_label="values", line_width=1)

    p.extra_y_ranges = {"Vol": Range1d(start=<<my_y1_range_1>>,end=<<my_y1_range_2>>)}
    p.line(x, y1, legend_label="my 2nd Y axis", line_color="red",y_range_name="Vol")
    p.varea(x=x,y1=<<my_range_1>>,y2=<<my_range_2>>,alpha=0.3)
    p.add_layout(LinearAxis(y_range_name="Vol"), 'right')

What attribute should I be using to mark the area labelled (y) with the color of my choice, thanks?

enter image description here


Solution

  • Did some more research and came up with the following:

    • the number of data points on the x axis is approx. 340.
    • the plot size (height x width) is 100 x 150

    In the above scenario (and ones similar to this), the background_fill_color appears to become irrelevant because there are 340 xgrid lines that overlay it. Suppressing the gridlines brings out the background_fill_color in this case.

    p.xgrid.grid_line_color = None
    

    or

    p.xgrid.visible = False
    

    Hopefully, this helps anyone else who runs into the same problem where you have a relatively large'ish set of data points vis-a-vis the plot size. Either enlarge the plot size, or alternatively suppress the gridlines (would seem like the grid lines are set to some sort of a 'show' mode by default, as opposed to 'enable/show' them only if I want to). I'm not complaining about the default behavior and am a big fan of bokeh and its simplicity. Salut to the folks who came up with it and who continue to contribute to it.