0

I am using mne package in Python for EEG plotting. I have a matplotlib figure instance and I want to plot two of them side by side and draw lines over it to show connections.

>>import mne
>>import matplotlib.pyplot as plt
>>a = mne.channels.read_montage('standard_1020')
>>b = a.plot()

Now I have b of type <class 'matplotlib.figure.Figure'> . I want to open two such side by side and draw lines over it.

thechargedneutron
  • 802
  • 1
  • 9
  • 24
  • The usual way to do that in `matplotlib` is to create two `Axes` instances in one `Figure`, and then its trivial to draw lines between them. However, `Montage.plot` from `mne` appears to hardwire it to create a new figure for each plot, so creating connections between them is not simple. Perhaps there's a way to transport an `Axes` instance from one `Figure` to another once its been created? – tmdavison Jun 12 '18 at 10:48
  • There is this, but I wouldn't know, what `mne` actually returns: https://stackoverflow.com/a/44023219/8881141 – Mr. T Jun 12 '18 at 11:01
  • Something like this answer shows how you might move the axes from one figure to another: https://stackoverflow.com/a/46906599/588071 – tmdavison Jun 12 '18 at 11:02
  • `a.plot()` seems to return the `figure` instance, so to get the `Axes` you would need to do `b.axes[0]` or something similar – tmdavison Jun 12 '18 at 11:03
  • A well designed API would allow to take an axes as input and plot to it. Unfortunately, many packages don't do that. A solution like the one linked to by @tom may help here, but it's sure suboptimal (and could fail in certain cases). – ImportanceOfBeingErnest Jun 12 '18 at 11:08
  • Interestingly, while the [`plot_montage`](https://github.com/mne-tools/mne-python/blob/5c3105ce3fba8d190520c260bd73e2978acdf0a7/mne/viz/montage.py#L8) function does not take an axes as input, the underlying [`plot_sensors`](https://github.com/mne-tools/mne-python/blob/5c3105ce3fba8d190520c260bd73e2978acdf0a7/mne/viz/utils.py#L1297) does. So there might a reason this is not exposed to the user, possibly because of other elements in the figure. You can check if you can directly use `plot_sensors`. – ImportanceOfBeingErnest Jun 12 '18 at 11:28

0 Answers0