legend
This commit is contained in:
@@ -11,7 +11,7 @@ from django.utils import timezone
|
||||
from bokeh.palettes import Dark2_8 as palette
|
||||
import itertools
|
||||
from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc
|
||||
from bokeh.models import CustomJS,Slider, TextInput
|
||||
from bokeh.models import CustomJS,Slider, TextInput,BoxAnnotation
|
||||
from bokeh.charts import Histogram,HeatMap,Area,BoxPlot
|
||||
from bokeh.resources import CDN,INLINE
|
||||
from bokeh.embed import components
|
||||
@@ -1189,7 +1189,7 @@ def interactive_chart(id=0,promember=0):
|
||||
|
||||
def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
||||
ploterrorbars=False,
|
||||
title=None,binsize=1):
|
||||
title=None,binsize=1,colorlegend=[]):
|
||||
|
||||
if datadf.empty:
|
||||
return ['','<p>No non-zero data in selection</p>']
|
||||
@@ -1259,18 +1259,17 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
||||
datadf,
|
||||
)
|
||||
|
||||
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,resize'
|
||||
|
||||
if groupby != 'date':
|
||||
hover = HoverTool(names=['data'],
|
||||
tooltips = [
|
||||
(groupby,'@groupval{1.1}')
|
||||
(groupby,'@groupval{1.1}'),
|
||||
])
|
||||
else:
|
||||
hover = HoverTool(names=['data'],
|
||||
tooltips = [
|
||||
(groupby,'@groupval')
|
||||
(groupby,'@groupval'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
@@ -1281,7 +1280,7 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
||||
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
|
||||
tools=TOOLS,
|
||||
toolbar_location="above",
|
||||
toolbar_sticky=False)
|
||||
toolbar_sticky=False) #,plot_width=500,plot_height=500)
|
||||
|
||||
# add watermark
|
||||
plot.extra_y_ranges = {"watermark": watermarkrange}
|
||||
@@ -1300,7 +1299,7 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
||||
x_range_name = "watermark",
|
||||
y_range_name = "watermark",
|
||||
)
|
||||
|
||||
|
||||
errorbar(plot,xparam,yparam,source=source,
|
||||
xerr=ploterrorbars,
|
||||
yerr=ploterrorbars,
|
||||
@@ -1311,6 +1310,34 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
for nr, gvalue, color in colorlegend:
|
||||
box = BoxAnnotation(bottom=500-20*nr,left=550,top=520-20*nr,
|
||||
right=570,
|
||||
bottom_units='screen',
|
||||
top_units='screen',
|
||||
left_units='screen',
|
||||
right_units='screen',
|
||||
fill_color=color)
|
||||
legendlabel = Label(x=571,y=503-20*nr,x_units='screen',
|
||||
y_units='screen',
|
||||
text = "{gvalue:3.0f}".format(gvalue=gvalue),
|
||||
background_fill_alpha=1.0,
|
||||
text_color='black',
|
||||
text_font_size=value("0.7em"))
|
||||
plot.add_layout(box)
|
||||
plot.add_layout(legendlabel)
|
||||
|
||||
if colorlegend:
|
||||
legendlabel = Label(x=372,y=300,x_units='screen',
|
||||
y_units='screen',
|
||||
text = 'group legend',
|
||||
text_color='black',
|
||||
text_font_size=value("0.7em"),
|
||||
angle=90,
|
||||
angle_units='deg')
|
||||
|
||||
if xparam == 'workoutid':
|
||||
plot.xaxis.axis_label = 'Workout'
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user