# Figure not getting plotted as per axis

**URL:** <https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366>\
**Category:** Community Support\
**Tags:** bokeh\
**Created:** [March 8, 2021, 6:29am UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366 "2021-03-08T06:29:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashish\_Kumar](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/ashish_kumar/32/3188_2.png) [@Ashish\_Kumar](https://discourse.bokeh.org/u/Ashish_Kumar)\
**Post date:** [March 8, 2021, 6:29am UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366/1 "2021-03-08T06:29:33Z")

</div>

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:-

```auto
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)

```

 ![image](https://discourse-uploads.bokeh.org/original/2X/c/c209f1c063bfdb7988ca4228fb641e06c4b15eb8.png)  
 ![image](https://discourse-uploads.bokeh.org/original/2X/e/efd6329eaca2d88dd6d0ecb67a1bd9416021dd4e.png)

Thanks

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [March 8, 2021, 6:27pm UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366/2 "2021-03-08T18:27:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ashish\_Kumar](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/ashish_kumar/32/3188_2.png) [@Ashish\_Kumar](https://discourse.bokeh.org/u/Ashish_Kumar)\
**Post date:** [March 8, 2021, 8:55pm UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366/3 "2021-03-08T20:55:59Z")

</div>

Hi Bryan,

How to do that.

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [March 8, 2021, 9:50pm UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366/4 "2021-03-08T21:50:50Z")

</div>

> [@Bryan](#):
>
> update `data` all at once with a completely new dict,

```auto
p.data_source.data = dict(xs=..., ys=...)

```

---

<div class="post-metadata">

**Author:** ![Ashish\_Kumar](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/ashish_kumar/32/3188_2.png) [@Ashish\_Kumar](https://discourse.bokeh.org/u/Ashish_Kumar)\
**Post date:** [March 9, 2021, 4:11am UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366/5 "2021-03-09T04:11:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [March 9, 2021, 6:12am UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366/6 "2021-03-09T06:12:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ashish\_Kumar](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/ashish_kumar/32/3188_2.png) [@Ashish\_Kumar](https://discourse.bokeh.org/u/Ashish_Kumar)\
**Post date:** [March 9, 2021, 5:18pm UTC](https://discourse.bokeh.org/t/figure-not-getting-plotted-as-per-axis/7366/7 "2021-03-09T17:18:36Z")

</div>

@Bryan

Thanks for the explanation
