import plotly.graph_objects as go import plotly import plotly.offline as pltoff def plot_mets(phone,actigraph): """ 画actigraph 和手机 cut point 转化为mets之后的点图 :param phone: df :param actigraph: df :return: """ fig = go.Figure(layout={"template": "plotly_white"}) # fig.add_trace(go.Scatter(x=time_list, y=phone_data_filter['magnitude'], # mode='lines', # name='phone_data_raw', # marker=dict(color='#06d6a0') # )) fig.add_trace(go.Scatter(x=time_list, y=phone, mode='markers', name='phone mets', marker=dict(color="#e6b800"), marker_symbol='x-open' )) fig.add_trace(go.Scatter(x=time_list, y=get_line(phone), mode='lines', name='phone mets line', line=dict(color="#e6b800",dash='dash',width=4) )) fig.add_trace(go.Scatter(x=actigraph_data_with_time['time'], y=actigraph, mode='markers', name='actigraph mets', marker_symbol="circle-open", marker=dict(color='#ff1a1a') )) fig.add_trace(go.Scatter(x=actigraph_data_with_time['time'], y=get_line(actigraph), mode='lines', name='actigraph mets line', line=dict(color="#ff1a1a",dash='dash',width=4) )) fig.add_trace(go.Scatter(x=mets['processed_time'], y=mets['mets'], mode='markers', name='K5 mets', marker_symbol="diamond-open", marker=dict(color="#0066ff") )) fig.add_trace(go.Scatter(x=mets['processed_time'], y=get_line_mets(mets['mets'],x_cache), mode='lines', name='K5 mets line', line=dict(color="#0066ff", dash='dash', width=4) )) fig.update_layout( ######################## 图例设置 ############################# legend=dict(x=0.1, y=1, # 设置图例的位置,[0,1]之间 font=dict(family='Times New Roman', size=30, color='black'), # 设置图例的字体及颜色 bordercolor="Black", borderwidth=2), xaxis = dict(mirror=True, ticks='outside', showline=False, showgrid=True, ), yaxis=dict(mirror='all', ticks='outside', showline=False, showgrid=True), # yaxis2=dict(anchor='x', overlaying='y', side='right'), # 设置坐标轴的格式,一般次坐标轴在右侧 # yaxis2_title='Mets', xaxis_title="Time", # X轴标题文本 yaxis_title="Mets", # Y轴标题文本 # legend_title="Legend Title", # 图例标题文本 font=dict( family="Times New Roman", # 所有标题文字的字体 size=40, # 所有标题文字的大小 color="black" # 所有标题的颜色 ), xaxis_title_font_family='Times New Roman', # 额外设置x轴标题的字体 yaxis_title_font_color='black', # 额外将y轴的字体设置为红色 ) # plotly.offline.plot(fig) # 导出图表 plotly.offline.plot(fig)