Here I want to plot the fault for every every sub plots according to there unit. how to use "facet_row" for "figline.add_scattergl(x=df2.DateTime, y=df2.Value.where(df2.DataType=="Fault"), name="Fault", line={'color': 'red'})" this line.
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()
df2 = pd.DataFrame([
dict(DateTime='2022-01-01 00:00:00', Value=90, Point="A", Unit='%', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:15:00', Value=80, Point="A", Unit='%', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:30:00', Value=85, Point="A", Unit='%', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:45:00', Value=92, Point="A", Unit='%', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 01:00:00', Value=100, Point="A", Unit='%', DataType='Fault',Type='Demo'),
dict(DateTime='2022-01-01 01:15:00', Value=72, Point="A", Unit='%', DataType='Fault',Type='Demo'),
dict(DateTime='2022-01-01 00:00:00', Value=22, Point="B", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:15:00', Value=22, Point="B", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:30:00', Value=23, Point="B", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:45:00', Value=20, Point="B", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 01:00:00', Value=21, Point="B", Unit='°C', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 01:15:00', Value=23, Point="B", Unit='°C', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 00:00:00', Value=24, Point="C", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:15:00', Value=24, Point="C", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:30:00', Value=24, Point="C", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:45:00', Value=24, Point="C", Unit='°C', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 01:00:00', Value=24, Point="C", Unit='°C', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 01:15:00', Value=24, Point="C", Unit='°C', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 00:00:00', Value=60, Point="D", Unit='Pa', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:15:00', Value=58, Point="D", Unit='Pa', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:30:00', Value=62, Point="D", Unit='Pa', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:45:00', Value=61, Point="D", Unit='Pa', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 01:00:00', Value=64, Point="D", Unit='Pa', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 01:15:00', Value=59, Point="D", Unit='Pa', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 00:00:00', Value=0, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:15:00', Value=0, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:30:00', Value=1, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 00:45:00', Value=1, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 01:00:00', Value=1, Point="E", Unit='Binary', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 01:15:00', Value=1, Point="E", Unit='Binary', DataType='Fault', Type='Demo'),
dict(DateTime='2022-01-01 01:30:00', Value=0, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 01:45:00', Value=0, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 02:00:00', Value=1, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 02:15:00', Value=1, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 02:30:00', Value=1, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
dict(DateTime='2022-01-01 02:45:00', Value=1, Point="E", Unit='Binary', DataType='Normal', Type='Demo'),
])
figline = px.line(df2, x="DateTime", y="Value", color="Point", line_group="Unit", hover_name="Point", facet_row="Unit",
line_shape="spline", render_mode="svg")
figline.update_yaxes(autorange=True)
figline.update_layout(hovermode="x unified")
figline.update_yaxes(matches=None)
#figline = highLights(fig = figline, dfChart=df2, variable = 'DataType', level = 'Fault', mode = 'Fault',
# fillcolor = 'rgba(200,0,200,0.2)', layer = 'below')
figline.add_scattergl(x=df2.DateTime, y=df2.Value.where(df2.DataType=="Fault"), name="Fault", line={'color': 'red'})
#figline.add_trace(go.Scatter(x=df2.DateTime, y=df2.Value.where(df2.DataType=="Fault"), name="Fault", line={'color': 'Gray'}))
figline.show()
The graph is supposed to like this: all the fault is over lapped on each line here the fault line is plotted in one subplot