Connectgaps in go.Scatter linegraph not working


My code for creating a line chart using plotly graph objects looks like this

> trace1 = go.Scatter(x=dframe.datetime, y=dframe['rssi'], name='Legal', \
> 	            mode='lines+markers', connectgaps=False, marker={'size': 8, "opacity": 0.6, 'color':list(map(setColor, dframe['legality']))}, hoverinfo='text', hovertext = hoverText)

Where datetime is date time formatted column in my dataframe ‘dframe’ . I need to show the gaps in the time series data and hence passed the parameter connectgaps = False, however I dont see the required result.

Heres a snapshot -

Please advice on the way to achieve this gap.


Hi @aiyer1,

Running help(go.Scatter) you’ll see the attributes of Scatter. connectgaps is described as follows:

 |          Determines whether or not gaps (i.e. {nan} or missing
 |          values) in the provided data arrays are connected. 

Hence you’ll get gaps displayed in your plot only if either your datetime column contains a space ’ ’ in some position or a nan in the y data.

import plotly.graph_objects as go
import datetime
import pandas as pd
import numpy as np

date = [, month=10, day=1),, month=10, day=2),, month=10, day=3),
        '',, month=10, day=5),, month=10, day=6),, month=10, day=7),, month=10, day=8)]

df = pd.DataFrame({'date':date, 'a':5+2*np.random.rand(8)})

trace = go.Scatter(, y=df['a'],
           mode='lines+markers', connectgaps=False)


Thanks @empet.
I saw that but wanted to know how to show gaps in teh data.

In my case the dataframe doesnt have any gaps in the datetime column or nan’s in the actual data itself however there is a ‘gap’ between the data recorded between the 18th and the 20th of Oct which gets shown as a straight line.

Does this mean that I will have to check the datetime column for discontinuity and add ‘nan’ in the y data for me to achieve the gaps on the graph??


@aiyer1 Such gaps are not identified by Plotly. You have to process your data and insert yourself a gap as it is recognized by plotly.js.

Understood…thanks @empet

three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online