问题
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