Black Lives Matter. Please consider donating to Black Girls Code today.

Connectgaps in go.Scatter linegraph not working

Hi,

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.

Cheers
Ananth

Hi @aiyer1,

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

connectgaps
 |          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.
Example:

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

date = [datetime.date(year=2019, month=10, day=1),
        datetime.date(year=2019, month=10, day=2),
        datetime.date(year=2019, month=10, day=3),
        '',
        datetime.date(year=2019, month=10, day=5),
        datetime.date(year=2019, month=10, day=6),
        datetime.date(year=2019, month=10, day=7),
        datetime.date(year=2019, month=10, day=8)]


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


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

fig=go.Figure(data=[trace])

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??

thanks
Ananth

@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

Hello @empet, (and others too!)

I see an issue connected to the topic I raised before and hence wanted to update here, hoping to find a reason why.

I am trying to plot multiple line graphs on top of another and have tried plotly express as well as plotly graph objects scatter plots but see as similar result as below…

Here is what the data looks like (first 100 rows) -

datetime freq rssi freq rssi freq rssi
09/12/2019 13:40 97.9 42 104.7 96.5 60
09/12/2019 14:20 97.9 42 104.7 96.5 60
09/12/2019 15:00 97.9 43 104.7 96.5 59
09/12/2019 15:43 97.9 43 104.7 52 96.5 59
09/12/2019 16:24 97.9 104.7 52 96.5 60
09/12/2019 17:05 97.9 44 104.7 52 96.5 60
09/12/2019 17:46 97.9 43 104.7 52 96.5 60
09/12/2019 18:26 97.9 43 104.7 52 96.5 60
09/12/2019 19:08 97.9 104.7 51 96.5 59
09/12/2019 19:51 97.9 41 104.7 51 96.5 60
09/12/2019 20:33 97.9 41 104.7 51 96.5 59
09/12/2019 21:14 97.9 42 104.7 52 96.5 59
09/12/2019 21:54 97.9 42 104.7 52 96.5 59
09/12/2019 22:32 97.9 42 104.7 52 96.5 60
09/12/2019 23:12 97.9 43 104.7 52 96.5 59
09/12/2019 23:55 97.9 42 104.7 52 96.5 60
10/12/2019 00:35 97.9 42 104.7 52 96.5 60
10/12/2019 01:14 97.9 43 104.7 52 96.5 60
10/12/2019 01:55 97.9 41 104.7 52 96.5 60
10/12/2019 02:36 97.9 43 104.7 52 96.5 59
10/12/2019 03:12 97.9 43 104.7 52 96.5 60
10/12/2019 03:54 97.9 44 104.7 52 96.5 60
10/12/2019 04:36 97.9 43 104.7 52 96.5 60
10/12/2019 05:16 97.9 42 104.7 52 96.5 60
10/12/2019 05:55 97.9 43 104.7 52 96.5 60
10/12/2019 06:39 97.9 44 104.7 52 96.5 59
10/12/2019 07:22 97.9 41 104.7 52 96.5 60
10/12/2019 08:02 97.9 104.7 96.5 59
10/12/2019 08:44 97.9 104.7 96.5 60
10/12/2019 09:24 97.9 43 104.7 96.5 60
10/12/2019 10:04 97.9 104.7 96.5 60
10/12/2019 10:41 97.9 40 104.7 96.5 60
10/12/2019 11:22 97.9 43 104.7 96.5 60
10/12/2019 12:02 97.9 104.7 96.5 58
10/12/2019 12:40 97.9 104.7 96.5 58
10/12/2019 13:21 97.9 40 104.7 96.5 59
10/12/2019 14:03 97.9 42 104.7 96.5 60
10/12/2019 14:43 97.9 41 104.7 96.5 61
10/12/2019 15:22 97.9 43 104.7 96.5 60
10/12/2019 16:01 97.9 42 104.7 55 96.5 60
10/12/2019 16:44 97.9 104.7 54 96.5 60
10/12/2019 17:22 97.9 41 104.7 54 96.5 60
10/12/2019 18:04 97.9 43 104.7 54 96.5 60
10/12/2019 18:47 97.9 40 104.7 52 96.5 60
10/12/2019 19:30 97.9 104.7 54 96.5 60
10/12/2019 20:11 97.9 104.7 52 96.5 58
10/12/2019 20:50 97.9 104.7 53 96.5 58
10/12/2019 21:30 97.9 104.7 52 96.5 58
10/12/2019 22:12 97.9 104.7 53 96.5 59
10/12/2019 22:54 97.9 104.7 53 96.5 60
11/12/2019 00:18 97.9 43 104.7 54 96.5 58
11/12/2019 00:59 97.9 43 104.7 54 96.5 59
11/12/2019 01:40 97.9 41 104.7 54 96.5 59
11/12/2019 02:18 97.9 43 104.7 54 96.5 60
11/12/2019 03:00 97.9 44 104.7 54 96.5 60
11/12/2019 03:43 97.9 42 104.7 54 96.5 60
11/12/2019 04:23 97.9 40 104.7 54 96.5 60
11/12/2019 05:04 97.9 43 104.7 54 96.5 60
11/12/2019 05:43 97.9 43 104.7 54 96.5 60
11/12/2019 06:24 97.9 104.7 54 96.5 60
11/12/2019 07:03 97.9 42 104.7 54 96.5 60
11/12/2019 07:44 97.9 43 104.7 54 96.5 60
11/12/2019 08:24 97.9 42 104.7 96.5 60
11/12/2019 09:04 97.9 43 104.7 96.5 60
11/12/2019 09:43 97.9 44 104.7 96.5 60
11/12/2019 10:21 97.9 42 104.7 96.5 61
11/12/2019 10:59 97.9 44 104.7 96.5 60
11/12/2019 11:39 97.9 44 104.7 96.5 60
11/12/2019 12:17 97.9 104.7 96.5 60
11/12/2019 13:00 97.9 44 104.7 96.5 60
11/12/2019 13:39 97.9 44 104.7 96.5 60
11/12/2019 14:19 97.9 44 104.7 96.5 60
11/12/2019 15:00 97.9 43 104.7 96.5 60
11/12/2019 15:40 97.9 38 104.7 96.5 60
11/12/2019 16:21 97.9 44 104.7 55 96.5 60
11/12/2019 17:05 97.9 44 104.7 54 96.5 60
11/12/2019 17:46 97.9 43 104.7 53 96.5 59
11/12/2019 18:25 97.9 44 104.7 54 96.5 59
11/12/2019 19:04 97.9 43 104.7 54 96.5 60
11/12/2019 19:46 97.9 42 104.7 54 96.5 60
11/12/2019 20:28 97.9 44 104.7 54 96.5 60
11/12/2019 21:12 97.9 43 104.7 54 96.5 60
11/12/2019 21:54 97.9 104.7 54 96.5 60
11/12/2019 22:35 97.9 42 104.7 54 96.5 60
11/12/2019 23:16 97.9 41 104.7 54 96.5 60
11/12/2019 23:57 97.9 41 104.7 54 96.5 60
12/12/2019 00:38 97.9 43 104.7 54 96.5 60
12/12/2019 01:21 97.9 42 104.7 54 96.5 60
12/12/2019 02:01 97.9 42 104.7 54 96.5 60
12/12/2019 02:43 97.9 104.7 54 96.5 60
12/12/2019 03:26 97.9 43 104.7 54 96.5 60
12/12/2019 04:07 97.9 44 104.7 54 96.5 60
12/12/2019 04:49 97.9 43 104.7 54 96.5 60
12/12/2019 05:30 97.9 44 104.7 54 96.5 60
12/12/2019 06:12 97.9 42 104.7 54 96.5 60
12/12/2019 06:56 97.9 42 104.7 54 96.5 60
12/12/2019 07:39 97.9 42 104.7 54 96.5 60
12/12/2019 08:22 97.9 43 104.7 96.5 59
12/12/2019 09:03 97.9 104.7 96.5 60

Plotly Express as well as go.Scatter both result in a plot like this

In some lines there is a gap (as expected, because of a ‘Nan’ ) however in some (Red line) there is a straight line rather than plotting the individual values in that interval. Could you please let me know what I am doing wrong here? I am expecting either a gap (for ‘NaNs’ or usual lines for values…)

cheers
ananth