colorful multiflex
This commit is contained in:
@@ -330,12 +330,12 @@ parchoicesmultiflex = list(sorted(formaxlabelsmultiflex.items(), key = lambda x:
|
|||||||
|
|
||||||
class MultiFlexChoiceForm(forms.Form):
|
class MultiFlexChoiceForm(forms.Form):
|
||||||
xparam = forms.ChoiceField(choices=parchoicesmultiflex,
|
xparam = forms.ChoiceField(choices=parchoicesmultiflex,
|
||||||
initial='spm',
|
initial='hr',
|
||||||
label='X axis')
|
label='X axis')
|
||||||
yparam = forms.ChoiceField(choices=parchoicesmultiflex,
|
yparam = forms.ChoiceField(choices=parchoicesmultiflex,
|
||||||
initial='power',
|
initial='pace',
|
||||||
label='Y axis')
|
label='Y axis')
|
||||||
groupby = forms.ChoiceField(choices=groupchoices,initial='date',
|
groupby = forms.ChoiceField(choices=groupchoices,initial='spm',
|
||||||
label='Group By')
|
label='Group By')
|
||||||
binsize = forms.FloatField(initial=1,required=False,label = 'Bin Size')
|
binsize = forms.FloatField(initial=1,required=False,label = 'Bin Size')
|
||||||
spmmin = forms.FloatField(initial=15,
|
spmmin = forms.FloatField(initial=15,
|
||||||
|
|||||||
@@ -81,17 +81,24 @@ def errorbar(fig, x, y, source=ColumnDataSource(),
|
|||||||
|
|
||||||
xerrvalues = source.data['xerror']
|
xerrvalues = source.data['xerror']
|
||||||
yerrvalues = source.data['yerror']
|
yerrvalues = source.data['yerror']
|
||||||
|
try:
|
||||||
|
colorvalues = source.data['color']
|
||||||
|
except KeyError:
|
||||||
|
colorvalues = ["#%02x%02x%02x" % (255,0,0) for x in xvalues]
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
a = xvalues[0]+1
|
a = xvalues[0]+1
|
||||||
if xerr:
|
if xerr:
|
||||||
x_err_x = []
|
x_err_x = []
|
||||||
x_err_y = []
|
x_err_y = []
|
||||||
for px, py, err in zip(xvalues, yvalues, xerrvalues):
|
err_color = []
|
||||||
|
for px, py, err, color in zip(xvalues, yvalues, xerrvalues, colorvalues):
|
||||||
x_err_x.append((px - err, px + err))
|
x_err_x.append((px - err, px + err))
|
||||||
x_err_y.append((py, py))
|
x_err_y.append((py, py))
|
||||||
fig.multi_line(x_err_x, x_err_y, color=color,
|
err_color.append(color)
|
||||||
|
|
||||||
|
fig.multi_line(x_err_x, x_err_y, color=err_color,
|
||||||
name='xerr',
|
name='xerr',
|
||||||
**error_kwargs)
|
**error_kwargs)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
@@ -102,10 +109,13 @@ def errorbar(fig, x, y, source=ColumnDataSource(),
|
|||||||
if yerr:
|
if yerr:
|
||||||
y_err_x = []
|
y_err_x = []
|
||||||
y_err_y = []
|
y_err_y = []
|
||||||
for px, py, err in zip(xvalues, yvalues, yerrvalues):
|
err_color = []
|
||||||
|
for px, py, err, color in zip(xvalues, yvalues, yerrvalues, colorvalues):
|
||||||
y_err_x.append((px, px))
|
y_err_x.append((px, px))
|
||||||
y_err_y.append((py - err, py + err))
|
y_err_y.append((py - err, py + err))
|
||||||
fig.multi_line(y_err_x, y_err_y, color=color,
|
err_color.append(color)
|
||||||
|
|
||||||
|
fig.multi_line(y_err_x, y_err_y, color=err_color,
|
||||||
name='yerr',**error_kwargs)
|
name='yerr',**error_kwargs)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
@@ -1279,13 +1289,15 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
|||||||
)
|
)
|
||||||
|
|
||||||
errorbar(plot,xparam,yparam,source=source,
|
errorbar(plot,xparam,yparam,source=source,
|
||||||
xerr=ploterrorbars,
|
xerr=ploterrorbars,
|
||||||
yerr=ploterrorbars,
|
yerr=ploterrorbars,
|
||||||
point_kwargs={
|
point_kwargs={
|
||||||
'line_color':None,
|
'line_color':None,
|
||||||
'legend':yparamname,
|
'legend':yparamname,
|
||||||
'size':"groupsize",
|
'size':"groupsize",
|
||||||
})
|
'fill_color':"color",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
if xparam == 'workoutid':
|
if xparam == 'workoutid':
|
||||||
plot.xaxis.axis_label = 'Workout'
|
plot.xaxis.axis_label = 'Workout'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
|
import colorsys
|
||||||
import timestring
|
import timestring
|
||||||
import zipfile
|
import zipfile
|
||||||
import bleach
|
import bleach
|
||||||
@@ -3571,7 +3572,8 @@ def multiflex_view(request,userid=0,
|
|||||||
|
|
||||||
#groupsize = 15.*np.log10(1+99.*groupsize/float(max(groupsize)))
|
#groupsize = 15.*np.log10(1+99.*groupsize/float(max(groupsize)))
|
||||||
groupsize = 30.*np.sqrt(groupsize/float(max(groupsize)))
|
groupsize = 30.*np.sqrt(groupsize/float(max(groupsize)))
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pd.DataFrame({
|
||||||
xparam:xvalues,
|
xparam:xvalues,
|
||||||
yparam:yvalues,
|
yparam:yvalues,
|
||||||
@@ -3579,18 +3581,35 @@ def multiflex_view(request,userid=0,
|
|||||||
'yerror':yerror,
|
'yerror':yerror,
|
||||||
'groupsize':groupsize,
|
'groupsize':groupsize,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
aantal = len(df)
|
||||||
|
|
||||||
if groupby != 'date':
|
if groupby != 'date':
|
||||||
try:
|
try:
|
||||||
df['groupval'] = groups.mean()[groupby],
|
df['groupval'] = groups.mean()[groupby],
|
||||||
|
groupcols = df['groupval']
|
||||||
except ValueError:
|
except ValueError:
|
||||||
df['groupval'] = groups.mean()[groupby].fillna(value=0)
|
df['groupval'] = groups.mean()[groupby].fillna(value=0)
|
||||||
|
groupcols = df['groupval']
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
df['groupval'] = [x.strftime("%Y-%m-%d") for x in groups.min()[groupby]]
|
df['groupval'] = [x.strftime("%Y-%m-%d") for x in groups.min()[groupby]]
|
||||||
|
groupcols = 100.*np.arange(aantal)/float(aantal)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
df['groupval'] = groups.mean()['days ago'].fillna(value=0)
|
df['groupval'] = groups.mean()['days ago'].fillna(value=0)
|
||||||
|
groupcols = 100.*np.arange(aantal)/float(aantal)
|
||||||
|
|
||||||
|
|
||||||
|
groupcols = (groupcols-groupcols.min())/(groupcols.max()-groupcols.min())
|
||||||
|
if aantal == 1:
|
||||||
|
groupcols = np.array([1.])
|
||||||
|
|
||||||
|
groupcols *= 100.
|
||||||
|
rgb = [colorsys.hsv_to_rgb(float(x/100.), 1.0, 1.0) for x in groupcols]
|
||||||
|
RGB = [(int(255.*r),int(255.*g),int(255.*b)) for (r, g, b) in rgb]
|
||||||
|
colors = ["#%02x%02x%02x" % (r, g, b) for (r, g, b) in RGB]
|
||||||
|
df['color'] = colors
|
||||||
|
|
||||||
if userid == 0:
|
if userid == 0:
|
||||||
extratitle = ''
|
extratitle = ''
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user