Figure not getting plotted as per axis

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 import output_notebook
from ipywidgets import interact
from bokeh.models.tickers import SingleIntervalTicker

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])

    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)['xs'] = x_plist['ys'] = y_plist

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


What happens if you update data all at once with a completely new dict, rather than updating the existing dict in place?

Hi Bryan,

How to do that. = dict(xs=..., ys=...)

Hi Bryan,
Thanks for the help. it is working now after your suggestion.

what is the difference between assigning the data as I was doing and assigning it as completely new dict

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.


Thanks for the explanation