Cant expand graph when a lot of points

I have a data to visualize, when a have 20 channels (20k points) I can expand them. However I can’t expand 48 channels (50k points), how do I fix it?

I use mne
n_channels = 48
ch_names = [str(i) for i in range(1,n_channels+1)]

data = data_orig.transpose()[:n_channels,:]
times = np.array(np.linspace(0,24,990))

# add channel names using Annotations
annotations = list([Annotation(x=-0.06, y=0, xref='paper', yref='y%d' % (ii + 1),
                                      text=ch_name, font=Font(size=9), showarrow=False)
                          for ii, ch_name in enumerate(ch_names)])

layout.update(annotations=annotations)

# set the size of the figure and plot it
layout.update(autosize=False, width=1000, height=800)
fig = Figure(data=traces, layout=layout)
py.iplot(fig, filename='shared xaxis')

Hi @alexyalunin,

I don’t think I understand what you mean by “expand”. Could you describe the behavior you want, and what you’re seeing?

Also, could you add complete examples of the working and not working behavior? These would include the imports, data, and plotting code so that folks can copy and paste them to reproduce what you’re seeing.

-Jon


With 20 channels I can do this thing with a gesture, however when I do this with 50 channels, they are not expanding.

import plotly
import plotly.plotly as py
import plotly.figure_factory as ff
plotly.tools.set_credentials_file(username='AlexYalunin', api_key='')
import plotly.graph_objs as go
from plotly import tools
from plotly.graph_objs import Layout, Scatter, Figure, Marker, Scattergl 
from plotly.graph_objs.layout import YAxis, Annotation, Font
from plotly.graph_objs.layout.annotation import Font

import mne
from mne.datasets import sample
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
mne.set_log_level('WARNING')

n_channels = 20
ch_names = [str(i) for i in range(1,n_channels+1)]

data = data_orig.transpose()[:n_channels,:]
times = np.array(np.linspace(0,24,990))

step = 1. / n_channels
kwargs = dict(domain=[1 - step, 1], showticklabels=False, zeroline=False, showgrid=False)

# create objects for layout and traces
layout = Layout(yaxis=YAxis(kwargs), showlegend=False)
traces = [Scattergl(x=times, y=data.T[:, 0])]

# loop over the channels
for ii in range(1, n_channels):
        kwargs.update(domain=[1 - (ii + 1) * step, 1 - ii * step])
        layout.update({'yaxis%d' % (ii + 1): YAxis(kwargs), 'showlegend': False})
        traces.append(Scatter(x=times, y=data.T[:, ii], yaxis='y%d' % (ii + 1)))

# add channel names using Annotations
annotations = list([Annotation(x=-0.06, y=0, xref='paper', yref='y%d' % (ii + 1),
                                      text=ch_name, font=Font(size=9), showarrow=False)
                          for ii, ch_name in enumerate(ch_names)])

layout.update(annotations=annotations)

# set the size of the figure and plot it
layout.update(autosize=False, width=1000, height=800)
fig = Figure(data=traces, layout=layout)
py.iplot(fig, filename='shared xaxis')

Hi @alexyalunin,

When I run the example I get this error

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-a22c6f18c6ef> in <module>
     20 ch_names = [str(i) for i in range(1,n_channels+1)]
     21 
---> 22 data = data_orig.transpose()[:n_channels,:]
     23 times = np.array(np.linspace(0,24,990))
     24 

NameError: name 'data_orig' is not defined

-Jon

try this example and try n_channels with 48 and 20

import plotly
import plotly.plotly as py
import plotly.figure_factory as ff
plotly.tools.set_credentials_file(username='AlexYalunin', api_key='')
import plotly.graph_objs as go
from plotly import tools
from plotly.graph_objs import Layout, Scatter, Figure, Marker, Scattergl 
from plotly.graph_objs.layout import YAxis, Annotation, Font
from plotly.graph_objs.layout.annotation import Font

import mne
from mne.datasets import sample
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
mne.set_log_level('WARNING')

n_channels = 48

data_orig = np.random.rand(48, 990)

ch_names = [str(i) for i in range(1,n_channels+1)]

data = data_orig.transpose()[:n_channels,:]
times = np.array(np.linspace(0,24,990))

step = 1. / n_channels
kwargs = dict(domain=[1 - step, 1], showticklabels=False, zeroline=False, showgrid=False)

# create objects for layout and traces
layout = Layout(yaxis=YAxis(kwargs), showlegend=False)
traces = [Scattergl(x=times, y=data.T[:, 0])]

# loop over the channels
for ii in range(1, n_channels):
        kwargs.update(domain=[1 - (ii + 1) * step, 1 - ii * step])
        layout.update({'yaxis%d' % (ii + 1): YAxis(kwargs), 'showlegend': False})
        traces.append(Scatter(x=times, y=data.T[:, ii], yaxis='y%d' % (ii + 1)))

# add channel names using Annotations
annotations = list([Annotation(x=-0.06, y=0, xref='paper', yref='y%d' % (ii + 1),
                                      text=ch_name, font=Font(size=9), showarrow=False)
                          for ii, ch_name in enumerate(ch_names)])

layout.update(annotations=annotations)

# set the size of the figure and plot it
layout.update(autosize=False, width=1000, height=800)
fig = Figure(data=traces, layout=layout)
py.iplot(fig, filename='shared xaxis')

Thanks for the example @alexyalunin, I see what you mean.

It looks like the zoom stops working when the y axes are spaced to closely together. For example, n_channels=48 works if I set the figure height to 1800.

Would it work for you to place all of these lines on the same axes, applying a constant y offset to each line?

-Jon