Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from numpy import linspace
from scipy.stats.kde import gaussian_kde
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, FixedTicker, PrintfTickFormatter
from bokeh.plotting import figure
from bokeh.sampledata.perceptions import probly
output_file("ridgeplot.html")
def ridge(category, data, scale=20):
return list(zip([category]*len(data), scale*data))
cats = list(reversed(probly.keys()))
palette = [cc.rainbow[i*15] for i in range(17)]
x = linspace(-20,110, 500)
source = ColumnDataSource(data=dict(x=x))
p = figure(y_range=cats, plot_width=900, x_range=(-5, 105), toolbar_location=None)
for i, cat in enumerate(reversed(cats)):
pdf = gaussian_kde(probly[cat])
y = ridge(cat, pdf(x))
source.add(y, cat)
p.patch('x', cat, color=palette[i], alpha=0.6, line_color="black", source=source)
p.outline_line_color = None
p.background_fill_color = "#efefef"
from numpy import linspace
from scipy.stats.kde import gaussian_kde
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, FixedTicker, PrintfTickFormatter
from bokeh.plotting import figure
from bokeh.sampledata.perceptions import probly
output_file("ridgeplot.html")
def ridge(category, data, scale=20):
return list(zip([category]*len(data), scale*data))
cats = list(reversed(probly.keys()))
palette = [cc.rainbow[i*15] for i in range(17)]
x = linspace(-20,110, 500)
source = ColumnDataSource(data=dict(x=x))
p = figure(y_range=cats, plot_width=700, x_range=(-5, 105), toolbar_location=None)
for i, cat in enumerate(reversed(cats)):
pdf = gaussian_kde(probly[cat])
y = ridge(cat, pdf(x))
source.add(y, cat)
p.patch('x', cat, color=palette[i], alpha=0.6, line_color="black", source=source)
p.outline_line_color = None
p.background_fill_color = "#efefef"
def trial_viewer(step_data, roll_type = "ewm", roll_span=100, bar=False):
"""
Args:
step_data:
grad_data:
"""
step_data.loc[step_data['response'] == 'L','response'] = 0
step_data.loc[step_data['response'] == 'R','response'] = 1
step_data.loc[step_data['target'] == 'L','target'] = 0
step_data.loc[step_data['target'] == 'R','target'] = 1
palette = [cc.rainbow[i] for i in range(len(step_data['subject'].unique()))]
palette = [cc.rainbow[i*15] for i in range(5)]
mice = sorted(step_data['subject'].unique())
current_step = step_data.groupby('subject').last().reset_index()
current_step = current_step[['subject','step']]
plots = []
p = figure(x_range=step_data['subject'].unique(),title='Subject Steps',
plot_height=200)
p.xaxis.major_label_orientation = np.pi / 2
p.vbar(x=current_step['subject'], top=current_step['step'], width=0.9)
plots.append(p)
for i, (mus, group) in enumerate(step_data.groupby('subject')):
if roll_type == "ewm":
meancx = group['correct'].ewm(span=roll_span,ignore_na=True).mean()
else:
def trial_viewer(step_data, grad_data):
"""
:param step_data:
:param grad_data:
"""
step_data.loc[step_data['response'] == 'L','response'] = 0
step_data.loc[step_data['response'] == 'R','response'] = 1
step_data.loc[step_data['target'] == 'L','target'] = 0
step_data.loc[step_data['target'] == 'R','target'] = 1
palette = [cc.rainbow[i] for i in range(len(step_data['mouse'].unique()))]
palette = [cc.rainbow[i*15] for i in range(5)]
mice = sorted(step_data['mouse'].unique())
current_step = step_data.groupby('mouse').last().reset_index()
current_step = current_step[['mouse','step']]
plots = []
p = figure(x_range=step_data['mouse'].unique(),title='Mouse Steps',
plot_height=200)
p.xaxis.major_label_orientation = np.pi / 2
p.vbar(x=current_step['mouse'], top=current_step['step'], width=0.9)
plots.append(p)
for i, (mus, group) in enumerate(step_data.groupby('mouse')):
meancx = group['correct'].ewm(span=100,ignore_na=True).mean()
p = figure(plot_height=100,y_range=(0,1),title=mus)
p.line(group['trial_num'], meancx, color=palette[group['step'].iloc[0]-1])