Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save filippchistiakov/fa7d4ba54041af211e1ac2da974509c0 to your computer and use it in GitHub Desktop.
Save filippchistiakov/fa7d4ba54041af211e1ac2da974509c0 to your computer and use it in GitHub Desktop.
plotly
df_desc=pd.DataFrame()
df_desc_no_out=pd.DataFrame()
for cur_tg in tqdm(df.teachers_group.unique()):
if cur_tg=='Математика':
frame_tg=df[df.teachers_group==cur_tg]
fig_subject_stats = plotly.tools.make_subplots(rows=6, cols=1, print_grid=False, subplot_titles=('Без выбросов',
'Все',
'Без выбросов. Распределение рабочих часов.',
'Все. Распределение рабочих часов.',
'Без выбросов. Распределение кол-ва проверенных работ.',
'Все. Распределение кол-ва проверенных работ.'
))
for grade in frame_tg.grade.unique():
name=cur_tg+' '+grade
########
frame=frame_tg[frame_tg.grade==grade]
frame['no_out']=~np.abs((frame.per_hour-frame.per_hour.mean()) < (2*frame.per_hour.std()))
#
df_desc=df_desc.append(pd.Series(frame.per_hour.describe(), name=grade))
df_desc_no_out=df_desc_no_out.append(pd.Series(frame[frame.no_out].per_hour.describe(), name=grade))
########
trace_no_out = go.Box(y=frame[frame.no_out].per_hour, name=grade+' Без выбросов')
fig_subject_stats.append_trace(trace_no_out, 1, 1)
#
trace = go.Box(y=frame.per_hour, name=grade+' Все')
fig_subject_stats.append_trace(trace, 2, 1)
trace_line2 = go.Scatter(x=df_desc_no_out.index+' Без выбросов', y=df_desc_no_out['mean'].values, name='Среднее. Без выбросов.')
fig_subject_stats.append_trace(trace_line2, 1, 1)
trace_line = go.Scatter(x=df_desc.index+' Все', y=df_desc['mean'].values, name='Среднее. Все.')
fig_subject_stats.append_trace(trace_line, 2, 1)
########
frame_tg['no_out']=~np.abs((frame_tg.per_hour-frame_tg.per_hour.mean()) < (2*frame_tg.per_hour.std()))
########
trace_hours_no_out = go.Histogram(x=frame_tg[frame_tg.no_out].count_hours_check.values,
name='Рабочих часов в среднем. Без выбросов.')
fig_subject_stats.append_trace(trace_hours_no_out, 3, 1)
trace_hours_all = go.Histogram(x=frame_tg.count_hours_check.values,
name='Рабочих часов в среднем. Все.')
fig_subject_stats.append_trace(trace_hours_all, 4, 1)
#
########
trace_ph_no_out = go.Histogram(x=frame_tg[frame_tg.no_out].per_hour.values,
name='Проверенно в час. Без выбросов.')
fig_subject_stats.append_trace(trace_ph_no_out, 5, 1)
#
trace_ph_all = go.Histogram(x=frame_tg.per_hour.values,
name='Проверенно в час. Все.')
fig_subject_stats.append_trace(trace_ph_all, 6, 1)
########
fig_subject_stats['layout'].update(title=cur_tg,
height=3000,
xaxis5=dict(range=[0, 50], tickvals=list(range(0, 50))),
xaxis6=dict(range=[0, 50], tickvals=list(range(0, 50))))
if check=='y':
#iplot(fig_subject_stats, filename=path+cur_tg+'.html')
plotly.offline.plot(fig_subject_stats, filename=path+cur_tg+'.html', auto_open=False)
print('Сохранен',path+cur_tg+'.html')
elif check=='n':
iplot(fig_subject_stats,filename=False)
else:
print('y или n только')
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment