Simplify plot creation in panel_ccl_compare
This commit is contained in:
parent
b57348b369
commit
f5814ddd5e
@ -8,40 +8,29 @@ import numpy as np
|
|||||||
from bokeh.io import curdoc
|
from bokeh.io import curdoc
|
||||||
from bokeh.layouts import column, row
|
from bokeh.layouts import column, row
|
||||||
from bokeh.models import (
|
from bokeh.models import (
|
||||||
BasicTicker,
|
|
||||||
Button,
|
Button,
|
||||||
CellEditor,
|
CellEditor,
|
||||||
CheckboxEditor,
|
CheckboxEditor,
|
||||||
CheckboxGroup,
|
CheckboxGroup,
|
||||||
ColumnDataSource,
|
ColumnDataSource,
|
||||||
CustomJS,
|
CustomJS,
|
||||||
DataRange1d,
|
|
||||||
DataTable,
|
DataTable,
|
||||||
Div,
|
Div,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
FileInput,
|
FileInput,
|
||||||
Grid,
|
|
||||||
Legend,
|
|
||||||
Line,
|
|
||||||
LinearAxis,
|
|
||||||
MultiLine,
|
|
||||||
MultiSelect,
|
MultiSelect,
|
||||||
NumberEditor,
|
NumberEditor,
|
||||||
Panel,
|
Panel,
|
||||||
PanTool,
|
|
||||||
Plot,
|
|
||||||
RadioGroup,
|
RadioGroup,
|
||||||
ResetTool,
|
|
||||||
Scatter,
|
|
||||||
Select,
|
Select,
|
||||||
Spacer,
|
Spacer,
|
||||||
Span,
|
Span,
|
||||||
Spinner,
|
Spinner,
|
||||||
TableColumn,
|
TableColumn,
|
||||||
TextAreaInput,
|
TextAreaInput,
|
||||||
WheelZoomTool,
|
|
||||||
Whisker,
|
Whisker,
|
||||||
)
|
)
|
||||||
|
from bokeh.plotting import figure
|
||||||
|
|
||||||
import pyzebra
|
import pyzebra
|
||||||
from pyzebra import AREA_METHODS, EXPORT_TARGETS
|
from pyzebra import AREA_METHODS, EXPORT_TARGETS
|
||||||
@ -225,17 +214,17 @@ def create():
|
|||||||
scan_table_source.data.update(fit=fit_ok, export=export)
|
scan_table_source.data.update(fit=fit_ok, export=export)
|
||||||
|
|
||||||
def _update_plot():
|
def _update_plot():
|
||||||
plot_scatter_source = [plot_scatter1_source, plot_scatter2_source]
|
scatter_sources = [scatter1_source, scatter2_source]
|
||||||
plot_fit_source = [plot_fit1_source, plot_fit2_source]
|
fit_sources = [fit1_source, fit2_source]
|
||||||
plot_bkg_source = [plot_bkg1_source, plot_bkg2_source]
|
bkg_sources = [bkg1_source, bkg2_source]
|
||||||
plot_peak_source = [plot_peak1_source, plot_peak2_source]
|
peak_sources = [peak1_source, peak2_source]
|
||||||
fit_output = ""
|
fit_output = ""
|
||||||
|
|
||||||
for ind, scan in enumerate(_get_selected_scan()):
|
for ind, scan in enumerate(_get_selected_scan()):
|
||||||
scatter_source = plot_scatter_source[ind]
|
scatter_source = scatter_sources[ind]
|
||||||
fit_source = plot_fit_source[ind]
|
fit_source = fit_sources[ind]
|
||||||
bkg_source = plot_bkg_source[ind]
|
bkg_source = bkg_sources[ind]
|
||||||
peak_source = plot_peak_source[ind]
|
peak_source = peak_sources[ind]
|
||||||
scan_motor = scan["scan_motor"]
|
scan_motor = scan["scan_motor"]
|
||||||
|
|
||||||
y = scan["counts"]
|
y = scan["counts"]
|
||||||
@ -278,59 +267,56 @@ def create():
|
|||||||
fit_output_textinput.value = fit_output
|
fit_output_textinput.value = fit_output
|
||||||
|
|
||||||
# Main plot
|
# Main plot
|
||||||
plot = Plot(
|
plot = figure(
|
||||||
x_range=DataRange1d(),
|
x_axis_label="Scan motor",
|
||||||
y_range=DataRange1d(only_visible=True),
|
y_axis_label="Counts",
|
||||||
plot_height=470,
|
plot_height=470,
|
||||||
plot_width=700,
|
plot_width=700,
|
||||||
|
tools="pan,wheel_zoom,reset",
|
||||||
)
|
)
|
||||||
|
|
||||||
plot.add_layout(LinearAxis(axis_label="Counts"), place="left")
|
scatter1_source = ColumnDataSource(dict(x=[0], y=[0], y_upper=[0], y_lower=[0]))
|
||||||
plot.add_layout(LinearAxis(axis_label="Scan motor"), place="below")
|
plot.circle(
|
||||||
|
source=scatter1_source,
|
||||||
plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
line_color="steelblue",
|
||||||
plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
fill_color="steelblue",
|
||||||
|
legend_label="data 1",
|
||||||
plot_scatter1_source = ColumnDataSource(dict(x=[0], y=[0], y_upper=[0], y_lower=[0]))
|
|
||||||
plot_scatter1 = plot.add_glyph(
|
|
||||||
plot_scatter1_source, Scatter(x="x", y="y", line_color="steelblue", fill_color="steelblue")
|
|
||||||
)
|
)
|
||||||
plot.add_layout(
|
plot.add_layout(Whisker(source=scatter1_source, base="x", upper="y_upper", lower="y_lower"))
|
||||||
Whisker(source=plot_scatter1_source, base="x", upper="y_upper", lower="y_lower")
|
|
||||||
|
scatter2_source = ColumnDataSource(dict(x=[0], y=[0], y_upper=[0], y_lower=[0]))
|
||||||
|
plot.circle(
|
||||||
|
source=scatter2_source,
|
||||||
|
line_color="firebrick",
|
||||||
|
fill_color="firebrick",
|
||||||
|
legend_label="data 2",
|
||||||
|
)
|
||||||
|
plot.add_layout(Whisker(source=scatter2_source, base="x", upper="y_upper", lower="y_lower"))
|
||||||
|
|
||||||
|
fit1_source = ColumnDataSource(dict(x=[0], y=[0]))
|
||||||
|
plot.line(source=fit1_source, legend_label="best fit 1")
|
||||||
|
|
||||||
|
fit2_source = ColumnDataSource(dict(x=[0], y=[0]))
|
||||||
|
plot.line(source=fit2_source, line_color="firebrick", legend_label="best fit 2")
|
||||||
|
|
||||||
|
bkg1_source = ColumnDataSource(dict(x=[0], y=[0]))
|
||||||
|
plot.line(
|
||||||
|
source=bkg1_source, line_color="steelblue", line_dash="dashed", legend_label="linear 1"
|
||||||
)
|
)
|
||||||
|
|
||||||
plot_scatter2_source = ColumnDataSource(dict(x=[0], y=[0], y_upper=[0], y_lower=[0]))
|
bkg2_source = ColumnDataSource(dict(x=[0], y=[0]))
|
||||||
plot_scatter2 = plot.add_glyph(
|
plot.line(
|
||||||
plot_scatter2_source, Scatter(x="x", y="y", line_color="firebrick", fill_color="firebrick")
|
source=bkg2_source, line_color="firebrick", line_dash="dashed", legend_label="linear 2"
|
||||||
)
|
|
||||||
plot.add_layout(
|
|
||||||
Whisker(source=plot_scatter2_source, base="x", upper="y_upper", lower="y_lower")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
plot_fit1_source = ColumnDataSource(dict(x=[0], y=[0]))
|
peak1_source = ColumnDataSource(dict(xs=[[0]], ys=[[0]]))
|
||||||
plot_fit1 = plot.add_glyph(plot_fit1_source, Line(x="x", y="y"))
|
plot.multi_line(
|
||||||
|
source=peak1_source, line_color="steelblue", line_dash="dashed", legend_label="peak 1"
|
||||||
plot_fit2_source = ColumnDataSource(dict(x=[0], y=[0]))
|
|
||||||
plot_fit2 = plot.add_glyph(plot_fit2_source, Line(x="x", y="y"))
|
|
||||||
|
|
||||||
plot_bkg1_source = ColumnDataSource(dict(x=[0], y=[0]))
|
|
||||||
plot_bkg1 = plot.add_glyph(
|
|
||||||
plot_bkg1_source, Line(x="x", y="y", line_color="steelblue", line_dash="dashed")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
plot_bkg2_source = ColumnDataSource(dict(x=[0], y=[0]))
|
peak2_source = ColumnDataSource(dict(xs=[[0]], ys=[[0]]))
|
||||||
plot_bkg2 = plot.add_glyph(
|
plot.multi_line(
|
||||||
plot_bkg2_source, Line(x="x", y="y", line_color="firebrick", line_dash="dashed")
|
source=peak2_source, line_color="firebrick", line_dash="dashed", legend_label="peak 2"
|
||||||
)
|
|
||||||
|
|
||||||
plot_peak1_source = ColumnDataSource(dict(xs=[[0]], ys=[[0]]))
|
|
||||||
plot_peak1 = plot.add_glyph(
|
|
||||||
plot_peak1_source, MultiLine(xs="xs", ys="ys", line_color="steelblue", line_dash="dashed")
|
|
||||||
)
|
|
||||||
|
|
||||||
plot_peak2_source = ColumnDataSource(dict(xs=[[0]], ys=[[0]]))
|
|
||||||
plot_peak2 = plot.add_glyph(
|
|
||||||
plot_peak2_source, MultiLine(xs="xs", ys="ys", line_color="firebrick", line_dash="dashed")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fit_from_span = Span(location=None, dimension="height", line_dash="dashed")
|
fit_from_span = Span(location=None, dimension="height", line_dash="dashed")
|
||||||
@ -339,25 +325,9 @@ def create():
|
|||||||
fit_to_span = Span(location=None, dimension="height", line_dash="dashed")
|
fit_to_span = Span(location=None, dimension="height", line_dash="dashed")
|
||||||
plot.add_layout(fit_to_span)
|
plot.add_layout(fit_to_span)
|
||||||
|
|
||||||
plot.add_layout(
|
plot.y_range.only_visible = True
|
||||||
Legend(
|
|
||||||
items=[
|
|
||||||
("data 1", [plot_scatter1]),
|
|
||||||
("data 2", [plot_scatter2]),
|
|
||||||
("best fit 1", [plot_fit1]),
|
|
||||||
("best fit 2", [plot_fit2]),
|
|
||||||
("peak 1", [plot_peak1]),
|
|
||||||
("peak 2", [plot_peak2]),
|
|
||||||
("linear 1", [plot_bkg1]),
|
|
||||||
("linear 2", [plot_bkg2]),
|
|
||||||
],
|
|
||||||
location="top_left",
|
|
||||||
click_policy="hide",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
|
||||||
plot.toolbar.logo = None
|
plot.toolbar.logo = None
|
||||||
|
plot.legend.click_policy = "hide"
|
||||||
|
|
||||||
# Scan select
|
# Scan select
|
||||||
def scan_table_select_callback(_attr, old, new):
|
def scan_table_select_callback(_attr, old, new):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user