nibabel
nibabel copied to clipboard
AttributeError raised in OrthoSlicer3D
I'm trying to visualize a volume using OrthoSlicer3D, but get a matplotlib error:
Script:
import numpy as np
from nibabel.viewers import OrthoSlicer3D as ov
data = np.ones((5, 5, 5))
ov(data)
Output:
Traceback (most recent call last):
File "ov.py", line 4, in <module>
ov(data)
File "/usr/local/Caskroom/miniconda/base/envs/torchio/lib/python3.8/site-packages/nibabel/viewers.py", line 213, in __init__
self._draw()
File "/usr/local/Caskroom/miniconda/base/envs/torchio/lib/python3.8/site-packages/nibabel/viewers.py", line 503, in _draw
ax.draw_artist(self._ims[ii])
File "/usr/local/Caskroom/miniconda/base/envs/torchio/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 2642, in draw_artist
raise AttributeError("draw_artist can only be used after an "
AttributeError: draw_artist can only be used after an initial draw which caches the renderer
Traceback (most recent call last):
File "/usr/local/Caskroom/miniconda/base/envs/torchio/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 196, in process
func(*args, **kwargs)
TypeError: _cleanup() takes 1 positional argument but 2 were given
Guessing this is with a recent matplotlib release? They may have made the method keyword only.
Yes, latest matplotlib and nibabel.
Oh, looks like @matthew-brett has chased this before: https://discourse.matplotlib.org/t/confusion-about-draw-artist/19891
I'm indeed using macOS.
I've also found this mysterious warning (cell [8]).
EDIT: Actually I just realized that you wrote that tutorial :)
I think this is a duplicate of #433, then. Sorry about the delay, but can you follow-up there, if you learn anything?
Well, I'll leave it to you to decide if this is a duplicate... Please close if so. :-)
I would say it's not, although they might be related. I'll keep you posted.
Any follow ups on this? I recently ran into the same problem.
I think this is a duplicate of #433, then. Sorry about the delay, but can you follow-up there, if you learn anything?
I'm using OSX 11.3.1 and I have got the same error. After I set matplotlib backend to TkAgg, it seems work right.
import nibabel as nib
from nibabel.viewers import OrthoSlicer3D
import matplotlib
matplotlib.use('TkAgg') # 注意这行要在 import plt之前 It should before import plt
from matplotlib import pylab as plt
Using the TkAgg backend, the viewer is shown, but
- The slices are black
- I can't close the figure
- I still get a
TypeError
I can see the image using img.orthoview() as suggested by @effigies in #433 (and TkAgg), but I get issues 2 and 3 of my previous comment.
Using the
TkAggbackend, the viewer is shown, but
- The slices are black
- I can't close the figure
- I still get a
TypeError
You should click the first window to change view location(it's normal black if the location is (0,0)).
And if the Python program is down(ctrl + Z), the figure will close.
You should click the first window to change view location(it's normal black if the location is (0,0)).
You're right, thanks!
And if the Python program is down(ctrl + Z), the figure will close.
This didn't work for me, but pressing q did.