☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Figure not getting plotted as per axis

Community Supportbokeh
Ashish_Kumar
Ashish_Kumar

Hi,
I m trying to interactively generate a plot using patches. I have written the logic to generate the data. Initially the plot works fine, but after using the slider the figure does not align with the axes. Not sure what is wrong with the code. In the first screen shot the plot is showing correctly , but in second screenshot same data the plot is showing differently
Below is the code used:-

from bokeh.plotting import figure, show
from bokeh.io import output_notebook
from ipywidgets import interact
from bokeh.models.tickers import SingleIntervalTicker
output_notebook()

plot = figure(width=300, height=300, x_range=(-x, x), y_range=(-y, y))
p = plot.patches('xs', 'ys', fill_alpha=.2, fill_color='red')
plot.axis.visible = True
plot.grid.visible = False


def update_data(x, y):
    x_plist = []
    y_plist = []
    for i in range(-x, x):
        for j in range(-y, y):
            x_plist.append([i, i, i+1, i+1])
            y_plist.append([j, j+1, j+1, j])

    print(x_plist[0])
    print(y_plist[0])
    plot.x_range.start = -x
    plot.y_range.start = -y

    plot.x_range.end = x
    plot.y_range.end = y

    plot.xaxis.ticker = SingleIntervalTicker(interval=1)
    plot.yaxis.ticker = SingleIntervalTicker(interval=1)

    p.data_source.data['xs'] = x_plist
    p.data_source.data['ys'] = y_plist
    push_notebook()


interact(update_data, x=5, y=12)
show(plot, notebook_handle=True)


Thanks

⌁   Link to post
Bryan
Bryan

A CDS similar to a DataFrame, and just like a DataFrame, all columns in a ColumnDataSource must have the same lengths at all times. That is a foundational assumption, that many things depend on, and one that is broken in your original code (in between the two assignments). Unfortunately the best we can do is warn about it retroactively (also seen above). Best practice with Bokeh is always to update .data all at once.

⌁   Link to post

End of archived discussion · Replies are disabled