-1

I have realized the dynamic graph drawing with matplotlib, and it can refresh graph real-time. Now, I want to generate matplot figure on Web Browers using mpld3. It can export to webpage, but can only run one time and graph won't be refreshed continuously. Wondering what this may be caused by? My script frame is as follow:

import mpld3[enter image description here][1]
from mpld3._server import serve
.
.
.
html1=mpld3.fig_to_html(fig1)
html2=mpld3.fig_to_html(fig2)
serve(html1+html2)
plt.pause(0.5)

enter image description here

Jiayu Sun
  • 3
  • 2
  • This is completely unclear. Do you have a webserver running python and want the webpage to continuously load new data from it? – ImportanceOfBeingErnest May 30 '18 at 12:46
  • First, I draw the graph using matplotlib from csv file, actually the graph can refresh data continuously and real-time. But now, I want to export the graph to webpage using mpld3 and hope the graph still can refresh data as I have done using matplotlib. Is there any way? – Jiayu Sun May 31 '18 at 01:59
  • The continuous refreshing of a matplotlib figure is done via events in a graphical user interface. This event handling mechanism is specific to a backend in use. The export to html only exports the figure and its elements, but of course you cannot call a Qt or Tk event to html - those are completely different languages. – ImportanceOfBeingErnest May 31 '18 at 08:57

1 Answers1

0

There is no way to do that.

However, you can still export your figure as a html file – as you already do with the mpld3.fig_to_html() command – but always in the same html file, and run a auto-reload soft in the web browser on this page (see for example this plugin for Firefox: https://addons.mozilla.org/en-US/firefox/addon/tab-auto-reload/).

But for mpld3 figures, the loading time can be quite large depending on the amount of data you are showing. This solution is definitely not appropriate for real-time applications!

Leonard
  • 2,510
  • 18
  • 37
  • So using mpld3 or mpld3.fig_to_html() can't export matplotlib figure to webpage which can real time refresh? Although I have realized auto-refresh with matplotlib. It just can export a static html file. – Jiayu Sun May 31 '18 at 02:11