Retrieve Data From Dynamic mpld3 plot in python

大兔子大兔子 提交于 2019-12-10 11:02:02

问题


I would like to update input data used to create an mpld3 generated python matplotlib list plot. Effectively, I have the same question as posted here:

Get point information after dragging

I'm familiar with python and matplotlib. sjp14051 had answered the above post, showing how to generate changes changes in point coordinates that are moved within the generated html plot. Could you please explain how the coordinate change generated from javascript can be moved back to the python environment to update the original input point[0] list used to generate the plot?

(If appropriate, please merge this with the referenced SO question.)


回答1:


Here is a medium-sized example of retrieving data from an mpld3 plot that I use to place call-outs on graphs. The simple approach to getting the data is to put it in a browser prompt:

function save_callouts(callouts) { function callout_py(d) { return "plt.text(" + d.x + ", " + d.y + ", '" + d.s + "', va='center')\n" + "plt.plot([" + d.x1 + ", " + d.x2 + "], [" + d.y1 + ", " + d.y2 + "], 'k-')\n" } prompt("Copy code to generate callouts:", callouts.map(callout_py).join("\n")); }

There might be slicker ways to accomplish this, but prompt followed by copy-and-paste on the user's part gets the job done.



来源:https://stackoverflow.com/questions/26532327/retrieve-data-from-dynamic-mpld3-plot-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!