0

I'm able to generate/show individual plots, but cannot seem to be able to aggregate multiple plots into a single gridplot. What am I doing wrong, thanks?

g = []
for item in basket:
    # sourcing and processing my data streams here
    # then moving to plotting the processed data into a single plot as below

    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=1000, plot_height=450,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')

    #show(p)                  <-- this works and displays the individual plot

    g.append(p)
# end/exit my for loop here

print (len(g))                <-- this prints out 3 in my test case
print (g)                     <-- [Figure(id='1001', ...), Figure(id='1066', ...), Figure(id='1131', ...)]

grid = gridplot(g)            <-- complains here

The exact error message I get is..

    grid = gridplot(g)
  File "\Python\Python35\lib\site-packages\bokeh\layouts.py", line 304, in gridplot
    for x, item in enumerate(row):
TypeError: 'Figure' object is not iterable

1 Answer 1

1

gridplot takes a list of lists (a list of rows), not a single 1d list. (Or if you really want, it does take a single 1d list, but you have to specify ncols in the call.)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, @bigreddot. Adding the ncols arg made the problem go away (and I want to use ncols in my gridplot spec). Could you help explain the situation as to what a list of rows means in the context. i.e., if I do not use ncols, I would have to specify which individual plots go in the first row, and which ones in the second row and so on?
Yes, exactly (a grid is inherently two dimensions).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.