pythonjsonplotlybokehmpld3

Python: How to get data from linked brushes in mlpd3, Bokeh, Plotly?


Using the code below I can get a 2x2 graph with 4 plots. With brushes, I can select some data points. The question I have is how do get the selected data points as a JSON array or cvs. This code uses mlpd3, but bokeh can do similar selections with brushes.. But there is no example of selecting the data points. I am trying to get selected data as object to continue processing with python. It would be nice to see the data in a cell.

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mat
import mpld3

mpld3.enable_notebook()


from mpld3 import plugins

fig, ax = plt.subplots(2, 2, figsize=(10, 8))
fig.subplots_adjust(hspace=0.1, wspace=0.1)
ax = ax[::-1]

X = np.random.normal(size=(2, 100))
for i in range(2):
    for j in range(2):
        ax[i, j].xaxis.set_major_formatter(plt.NullFormatter())
        ax[i, j].yaxis.set_major_formatter(plt.NullFormatter())
        points = ax[i, j].scatter(X[j], X[i])

plugins.connect(fig, plugins.LinkedBrush(points))

Bokeh has similar behavior in CustomJS for Selections

http://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html#userguide-interaction-jscallbacks-customjs-interactions

Whichever one is easier to extract the selected item -- would work.. If there is a Plotly solution, that would also work.


Solution

  • This is outside of ipython but you can run flask or django in conjunction with d3.js and jquery to get the data back into python.