3

I generated a figure using mpld3 and linked it to plugins.MousePosition() to display the coordinates, as below.

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import mpld3
from mpld3 import plugins, utils

x,y = np.random.rand(2,10)
fig, ax = plt.subplots()
ax.scatter(x,y,s=10,c='orange')

plugins.connect(fig, plugins.MousePosition())
mpld3.show()

The mouse position is reported in the lower right hand corner, which means the x,y coordinates can be read somehow. Is there a way to use the coordinate information to draw a polygon based on mouse click(s) and double click?

sjp14051
  • 99
  • 9

1 Answers1

2

This would be possible, but you'd essentially have to create a simple drawing program in d3/javascript, and then create a plugin that includes the javascript implementation.

I found a forum thread that might be of interest on this subject: https://groups.google.com/forum/#!msg/d3-js/zRgsx65hpWg/ivR0xwMPQt8J

jakevdp
  • 77,104
  • 11
  • 125
  • 160
  • Thanks @jakevdp. I circumvented the problem by first placing a polygon in the graph (implemented with a modified version of LinkedDragPlugin) and letting the user drag and move the vertices around. This is not the same as creating and destroying a polygon but for what I wanted to do, i.e. creating a gate for generating a histogram on the followup POST request, it worked ok. – sjp14051 Aug 19 '14 at 20:31