简体   繁体   English

在情节线图中,有没有办法设置情节不加入不同标签之间的间隙?

[英]In plotly line plot, is there a way to set plotly to not join the gaps between different labels?

I have attached a screenshot to my problem, but basically this is data of activity when the subject is awake and asleep, and the red is for when he is asleep.我已经为我的问题附上了屏幕截图,但基本上这是受试者清醒和睡着时的活动数据,红色是他睡着时的活动数据。 Is there a way to not have the blue lines connect to each other?有没有办法不让蓝线相互连接?


px.line(df["Axis1"], color = df["is_asleep"])

screenshot of the plot剧情截图

The ability to exclude holidays and certain times of the day has been added as a range-breaking feature.排除节假日和一天中某些时间的功能已添加为范围破坏功能。 However, this is only effective when there is missing in one time series data, and in the example of your data, the first time series, the next time series, and the last time series would be drawn.但是,这仅在一个时间序列数据缺失时有效,并且在您的数据示例中,将绘制第一个时间序列、下一个时间序列和最后一个时间序列。 Since you did not present any data, I will create similar data to illustrate.由于您没有提供任何数据,我将创建类似的数据来说明。

import pandas as pd
import numpy as np

# sample data
df1 = pd.DataFrame({'time':pd.date_range('2022-06-01 00:00:00', '2022-06-01 12:00:00', freq='10min'), 'name':['a']*73, 'value': np.random.randint(0,3000,73)})
df2 = pd.DataFrame({'time':pd.date_range('2022-06-01 12:00:00', '2022-06-02 00:00:00', freq='10min'), 'name':['br']*73, 'value': np.random.randint(0,1000,73)})
df3 = pd.DataFrame({'time':pd.date_range('2022-06-02 00:00:00', '2022-06-02 12:00:00', freq='10min'), 'name':['a']*73, 'value': np.random.randint(0,3000,73)})
df = pd.concat([df1,df2,df3], axis=0, ignore_index=True)

import plotly.express as px

px.line(df, x=df['time'], y=df['value'], color='name')

在此处输入图像描述

 # use rangebreaks

fig = px.line(df, x=df['time'], y=df['value'], color='name')

fig.update_xaxes(
    rangebreaks=[
        dict(bounds=[12,0], pattern='hour')
    ]
)
fig.show()

在此处输入图像描述

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Scatter(
    mode='lines',
    x=df1['time'],
    y=df1['value'],
    line=dict(
        color='blue',
        width=2,
        ),
    name='a'
    )
)

fig.add_trace(go.Scatter(
    mode='lines',
    x=df2['time'],
    y=df2['value'],
    line=dict(
        color='red',
        width=2,
        ),
    name='br'
    )
)

fig.add_trace(go.Scatter(
    mode='lines',
    x=df3['time'],
    y=df3['value'],
    line=dict(
        color='blue',
        width=2,
        ),
    name='a',
    showlegend=False,
    )
)

fig.show()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM