multi flex chart
This commit is contained in:
@@ -69,27 +69,46 @@ watermarkw = 184
|
||||
watermarkh = 35
|
||||
watermarkanchor = 'bottom_right'
|
||||
|
||||
def errorbar(fig, x, y, xerr=None, yerr=None, color='red',
|
||||
def errorbar(fig, x, y, source=ColumnDataSource(),
|
||||
xerr=False, yerr=False, color='red',
|
||||
point_kwargs={}, error_kwargs={}):
|
||||
|
||||
fig.circle(x, y, color=color, **point_kwargs)
|
||||
|
||||
if xerr:
|
||||
x_err_x = []
|
||||
x_err_y = []
|
||||
for px, py, err in zip(x, y, xerr):
|
||||
x_err_x.append((px - err, px + err))
|
||||
x_err_y.append((py, py))
|
||||
fig.multi_line(x_err_x, x_err_y, color=color, **error_kwargs)
|
||||
fig.circle(x, y, source=source, name='data',color=color, **point_kwargs)
|
||||
|
||||
if yerr:
|
||||
y_err_x = []
|
||||
y_err_y = []
|
||||
for px, py, err in zip(x, y, yerr):
|
||||
y_err_x.append((px, px))
|
||||
y_err_y.append((py - err, py + err))
|
||||
fig.multi_line(y_err_x, y_err_y, color=color, **error_kwargs)
|
||||
|
||||
xvalues = source.data[x]
|
||||
yvalues = source.data[y]
|
||||
|
||||
xerrvalues = source.data['xerror']
|
||||
yerrvalues = source.data['yerror']
|
||||
|
||||
|
||||
try:
|
||||
a = xvalues[0]+1
|
||||
if xerr:
|
||||
x_err_x = []
|
||||
x_err_y = []
|
||||
for px, py, err in zip(xvalues, yvalues, xerrvalues):
|
||||
x_err_x.append((px - err, px + err))
|
||||
x_err_y.append((py, py))
|
||||
fig.multi_line(x_err_x, x_err_y, color=color,
|
||||
name='xerr',
|
||||
**error_kwargs)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
a = yvalues[0]+1
|
||||
if yerr:
|
||||
y_err_x = []
|
||||
y_err_y = []
|
||||
for px, py, err in zip(xvalues, yvalues, yerrvalues):
|
||||
y_err_x.append((px, px))
|
||||
y_err_y.append((py - err, py + err))
|
||||
fig.multi_line(y_err_x, y_err_y, color=color,
|
||||
name='yerr',**error_kwargs)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
def tailwind(bearing,vwind,winddir):
|
||||
""" Calculates head-on head/tailwind in direction of rowing
|
||||
|
||||
@@ -1144,6 +1163,98 @@ def interactive_chart(id=0,promember=0):
|
||||
|
||||
return [script,div]
|
||||
|
||||
def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
||||
ploterrorbars=False):
|
||||
if datadf.empty:
|
||||
return ['','<p>No non-zero data in selection</p>']
|
||||
|
||||
|
||||
xparamname = axlabels[xparam]
|
||||
yparamname = axlabels[yparam]
|
||||
|
||||
if xparam=='distance':
|
||||
xaxmax = datadf['x1'].max()
|
||||
xaxmin = datadf['x1'].min()
|
||||
else:
|
||||
xaxmax = yaxmaxima[xparam]
|
||||
xaxmin = yaxminima[xparam]
|
||||
|
||||
x_axis_type = 'linear'
|
||||
y_axis_type = 'linear'
|
||||
if xparam == 'time':
|
||||
x_axis_type = 'datetime'
|
||||
if yparam == 'pace':
|
||||
y_axis_type = 'datetime'
|
||||
|
||||
source = ColumnDataSource(
|
||||
datadf,
|
||||
)
|
||||
|
||||
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,resize,hover'
|
||||
|
||||
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
|
||||
tools=TOOLS,
|
||||
toolbar_location="above",
|
||||
toolbar_sticky=False)
|
||||
# add watermark
|
||||
plot.extra_y_ranges = {"watermark": watermarkrange}
|
||||
plot.extra_x_ranges = {"watermark": watermarkrange}
|
||||
|
||||
plot.image_url([watermarkurl],watermarkx,watermarky,
|
||||
watermarkw,watermarkh,
|
||||
global_alpha=watermarkalpha,
|
||||
w_units='screen',
|
||||
h_units='screen',
|
||||
anchor=watermarkanchor,
|
||||
dilate=True,
|
||||
x_range_name = "watermark",
|
||||
y_range_name = "watermark",
|
||||
)
|
||||
|
||||
errorbar(plot,xparam,yparam,source=source,
|
||||
xerr=ploterrorbars,
|
||||
yerr=ploterrorbars,
|
||||
point_kwargs={
|
||||
'line_color':None,
|
||||
'legend':yparamname,
|
||||
'size':10,
|
||||
})
|
||||
|
||||
plot.xaxis.axis_label = axlabels[xparam]
|
||||
plot.yaxis.axis_label = axlabels[yparam]
|
||||
|
||||
|
||||
yrange1 = Range1d(start=yaxminima[yparam],end=yaxmaxima[yparam])
|
||||
plot.y_range = yrange1
|
||||
|
||||
xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam])
|
||||
plot.x_range = xrange1
|
||||
|
||||
if yparam == 'pace':
|
||||
plot.yaxis[0].formatter = DatetimeTickFormatter(
|
||||
seconds = ["%S"],
|
||||
minutes = ["%M"]
|
||||
)
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
if groupby != 'date':
|
||||
hover.tooltips = OrderedDict([
|
||||
(groupby,'@groupval{1.1}'),
|
||||
])
|
||||
else:
|
||||
hover.tooltips = OrderedDict([
|
||||
(groupby,'@groupval'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
script,div = components(plot)
|
||||
|
||||
|
||||
return [script,div]
|
||||
|
||||
def interactive_cum_flex_chart2(theworkouts,promember=0,
|
||||
xparam='spm',
|
||||
yparam1='power',
|
||||
|
||||
Reference in New Issue
Block a user