question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Colorbar labels overlap in Brain plot without time viewer

See original GitHub issue

When plotting an STC without the time viewer, the colorbar is arranged horizontally, causing the individual labels to overlap depending on the window size:

# %%
from pathlib import Path
import mne

mne.viz.set_3d_backend('pyvistaqt')
sample_dir = Path(mne.datasets.sample.data_path())
stc_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis-meg'  # omit suffix
fs_subject = 'sample'
fs_subjects_dir = sample_dir / 'subjects'

stc = mne.read_source_estimate(fname=stc_fname, subject=fs_subject)

stc.plot(
    time_viewer=False,
    size=(300, 300),
    subjects_dir=fs_subjects_dir
)
Screen Shot 2021-12-14 at 17 48 16

I’d suggest to only label the anchors and midpoint.

cc @GuillaumeFavelier

❯ mne sys_info
Platform:       macOS-12.1-x86_64-i386-64bit
Python:         3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 20:33:18)  [Clang 11.1.0 ]
Executable:     /Users/hoechenberger/miniforge3/envs/mne/bin/python3.9
CPU:            i386: 8 cores
Memory:         16.0 GB

mne:            1.0.dev0
numpy:          1.21.4 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy:          1.7.3
matplotlib:     3.5.0 {backend=MacOSX}

sklearn:        1.0.1
numba:          0.53.1
nibabel:        3.2.1
nilearn:        0.8.1
dipy:           1.4.1
cupy:           Not found
pandas:         1.3.4
pyvista:        0.32.1 {OpenGL 4.1 INTEL-18.3.5 via Intel(R) Iris(TM) Plus Graphics OpenGL Engine}
pyvistaqt:      0.5.0
ipyvtklink:     0.2.1
vtk:            9.0.3
PyQt5:          5.12.3
ipympl:         0.8.2
mne_qt_browser: 0.1.7
pooch:          v1.5.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
larsonercommented, Dec 15, 2021

Personally I’d also like it to be easy to set the colorbar tick values/locations manually…

Fun fact, this wasn’t even possible in even the dev version of VTK until 9 months ago, mostly (I think?) because ParaView had their own subclass that did something similar. Fortunately it does look like VTK 9.1 included the change that allows doing it:

>>> brain = stc.plot(...)
>>> from vtk.util import numpy_support 
>>> numpy_support.numpy
>>> import numpy as np
>>> brain.plotter.scalar_bar.SetCustomLabels(numpy_support.numpy_to_vtk(np.array([4, 5, 17], float)))
>>> brain.plotter.scalar_bar.SetUseCustomLabels(True)
Screen Shot 2021-12-14 at 7 09 17 PM

To me the best place to make all this accessible would be to subclass vtkScalarBarActor and implement at the PyVista backend as I mentioned above. The vtkScalarBarActor is currently accessible via brain.plotter.scalar_bar and brain._scalar_bar, so I say we change it to brain.scalar_bar (public name) and then make brain.scalar_bar have nice methods at the PyVista level. It’s much more in PyVista’s scope to provide convenience wrappers for VTK “stuff” than MNE-Python, so I’d rather work to solve the problem / implement a solution at their end with the help of their expertise!

1reaction
drammockcommented, Dec 14, 2021

Maybe we can discuss some ideas on Friday? 😃

Sure

Do you see this problem in your daily work?

Not daily, but it does come up, and it does annoy me. Personally I’d also like it to be easy to set the colorbar tick values/locations manually… e.g. if I’m plotting negative log10 of a p-value on the brain, then certain specific values are interesting / important to signpost

Read more comments on GitHub >

github_iconTop Results From Across the Web

Colorbar axis label overlapping with ticks Matplotlib
I am plotting a scatterplot with a colorbar on the right using Matplotlib. The labels of the colorbar get overlapped/get too close with...
Read more >
mne.viz.Brain — MNE 1.2.2 documentation
This is useful for viewing inflated surface where hemispheres typically overlap. Can be “auto” (default) use True with inflated surfaces and ...
Read more >
Prevent colorbar label overlapping with subplots axis
An issue I regularly encounter is the titles for colour bars overlapping with the titles for the y-axis of a neighbouring subplot; and, ......
Read more >
The fsbrain FAQ
If you experience this error, it most likely happened when you tried to plot something with a colorbar, and did not increase the...
Read more >
surfer.Brain - PySurfer 0.10.0 documentation
If two hemispheres are being shown, an error will be thrown. remove_existingbool. If there is an existing contour overlay, remove it before plotting....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found