forked from glue-viz/glue-plotly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogram.py
31 lines (21 loc) · 964 Bytes
/
histogram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from glue.config import viewer_tool
from glue_plotly.common import data_count, layers_to_export
from glue_plotly.common.histogram import layout_config, traces_for_layer
from plotly.offline import plot
import plotly.graph_objs as go
from ...jupyter_base_export_tool import JupyterBaseExportTool
@viewer_tool
class PlotlyHistogramBqplotExport(JupyterBaseExportTool):
tool_id = 'save:bqplot_plotlyhist'
def save_figure(self, filepath):
if not filepath:
return
config = layout_config(self.viewer, bargap=0.1)
layout = go.Layout(**config)
fig = go.Figure(layout=layout)
layers = layers_to_export(self.viewer)
add_data_label = data_count(layers) > 1
for layer in layers:
traces = traces_for_layer(self.viewer.state, layer.state, add_data_label=add_data_label)
fig.add_traces(traces)
plot(fig, include_mathjax='cdn', filename=filepath, auto_open=False)