glue-viz / glue-plotly

Experimental plot.ly plugin for glue
BSD 3-Clause "New" or "Revised" License
2 stars 8 forks source link

Implementation of Plotly viewers and refactoring #40

Closed Carifio24 closed 1 year ago

Carifio24 commented 1 year ago

This PR takes a first step at addressing #3 by providing basic POC implementations of Plotly-based 2D scatter and histogram Jupyter viewers. Additionally, this PR contains some refactoring aimed at making as much of the code be frontend-agnostic as possible - in addition to powering Plotly viewers, it would also be nice to reuse much of what we have to make exporters for other frontends (i.e. bqplot). I started with the 2D scatter and histogram viewers because they're pretty standard visualizations, and we're interested in potentially using these with CosmicDS.

As of now, these viewers are a work in progress and undoubtedly still have some issues. The current state of things looks like this:

General viewers:

Scatter viewer:

Histogram viewer:

Generally speaking, most of the logic for representing these items in Plotly traces has been worked out in the static exporters, so it's just a matter of making these traces respond to updates in the state.

If someone is interested in trying these out:

Install this branch: pip install git+https://github.com/Carifio24/glue-plotly@viewers

Here's a sample snippet to run in a Jupyter notebook:

from glue.core import Data
from glue_jupyter import jglue
from glue_plotly.viewers.histogram.viewer import PlotlyHistogramView
from glue_plotly.viewers.scatter.viewer import PlotlyScatterView

app = jglue()
session = app.session
dc = app.session.data_collection

from random import randint
data = Data(label='data', x=[randint(0, 100) for _ in range(100)], y=[randint(0, 100) for _ in range(100)])
dc.append(data)

viewer = app.new_data_viewer(PlotlyScatterView, data=data)
Carifio24 commented 1 year ago

The viewers don't yet implement everything that they could (that is, everything that the exporters support), but they do implement almost everything exposed through the glue-jupyter UI, so I think that's a good start.

@astrofrog Would be interested to hear any thoughts you have on either part of this PR (refactoring to use state, and the viewers)