I use django and create web page. Then I click button seaborn do not update data, only add data. Scatters are added to the plot as many times as I click the button. However I want reset existing data and show new plot by new data.
What is this sns object you’re referencing at sns.scatterplot(data=newdf_pl, x='Area', y='Price_G')? Where is it initialized? How is the view getting access to it?
Thanks for the feedback. I do not understand How is the view getting access to it. I view plot in web page. how can I initialize and update data in sns, every button click? I understand that need initialize, however how?
Yes, I understand and I am also surprised that it passes the view without assignment. This is probably where the problem comes from, because it doesn’t update every time.
About the best / safest solution I can think of would be to set up an external worker to process these requests, making sure the data components are initialized at the beginning of each request. (It might even be better / easier to launch a separate process to do this on each request. That way you can ensure that there’s no “global state” to be concerned about.)
But the bottom line is that I don’t expect that you’re going to find a clean way of doing this directly “in-line” as you’re trying to do here. Those components (pandas and matplotlib) are not particularly “friendly” to the Django environment.
To be clear, I am not recommending that you use chart.js.
Yes, using chart.js is an option.
However, if you really want to use the combination of Pandas, Matplotlib, and Seaborn, you can. It’s just going to require a bit more work on your part to make it stable and reliable. But it can be done.
It’s your choice where to spend your time and effort.