我正在尝试使用groupby函数以绘图方式创建折线图,但它似乎无法正常工作。 来自csv的数据在所附图片中。
我能够为图片1中的所有数据点生成通用绘图,但我的目标是为csv中“插槽”中的每个条目使用单独的彩色线。
import plotly
plotly.tools.set_credentials_file(username='xxxxx', api_key='yyyyy')
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as FF
import numpy as np
import pandas as pd
df = pd.read_csv('Trial_Original.csv')
trial_table = FF.create_table(df.head())
py.iplot(trial_table, filename='trial-table')
trace1 = go.Scatter(x=df['Time'], y=df['PS1_MON (A)'], mode='lines', name='iMon')
trace2 = go.Scatter(x=df['Time'], y=df['iskt_Pw (W)'], mode='lines', name='SP')
trace3 = go.Scatter(x=df['Time'], y=df['iskt_Case (C)'], mode='lines', name='CT')
layout1 = go.Layout(title='PS1-Current', showlegend=True, xaxis=dict(title='Time', autorange=True, titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f')), yaxis=dict(title='Current(A)',titlefont=dict(family='Courier New, monospace',size=18,color='#7f7f7f')), plot_bgcolor='rgb(230, 230,230)', transforms = [dict(type = 'groupby', groups = df['Slot'], styles = opts)])
layout2 = go.Layout(title='Socket-Power', showlegend=True, xaxis=dict(title='Time', autorange=True, titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f')), yaxis=dict(title='Power(W)',titlefont=dict(family='Courier New, monospace',size=18,color='#7f7f7f')), plot_bgcolor='rgb(230, 230,230)')
layout3 = go.Layout(title='Case-Temp', showlegend=True, xaxis=dict(title='Time', autorange=True, titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f')), yaxis=dict(title='Temp(C)',titlefont=dict(family='Courier New, monospace',size=18,color='#7f7f7f')), plot_bgcolor='rgb(230, 230,230)')
fig1 = go.Figure(data=[trace1], layout=layout1)
fig2 = go.Figure(data=[trace2], layout=layout2)
fig3 = go.Figure(data=[trace3], layout=layout3)
# Plot data in the notebook
py.iplot(fig1, filename='PS1-Current')
py.iplot(fig2, filename='Socket-Power')
py.iplot(fig3, filename='Case-Temp')