nibabel icon indicating copy to clipboard operation
nibabel copied to clipboard

AttributeError raised in OrthoSlicer3D

Open fepegar opened this issue 5 years ago • 12 comments

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

fepegar avatar Jun 04 '20 09:06 fepegar

Guessing this is with a recent matplotlib release? They may have made the method keyword only.

effigies avatar Jun 04 '20 11:06 effigies

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.

fepegar avatar Jun 04 '20 13:06 fepegar

I've also found this mysterious warning (cell [8]).

EDIT: Actually I just realized that you wrote that tutorial :)

fepegar avatar Jun 05 '20 23:06 fepegar

I think this is a duplicate of #433, then. Sorry about the delay, but can you follow-up there, if you learn anything?

effigies avatar Aug 02 '20 15:08 effigies

Well, I'll leave it to you to decide if this is a duplicate... Please close if so. :-)

effigies avatar Aug 02 '20 15:08 effigies

I would say it's not, although they might be related. I'll keep you posted.

fepegar avatar Aug 02 '20 15:08 fepegar

Any follow ups on this? I recently ran into the same problem.

0xSMT avatar Jan 22 '21 16:01 0xSMT

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

Asterisci avatar May 25 '21 11:05 Asterisci

Using the TkAgg backend, the viewer is shown, but

  1. The slices are black
  2. I can't close the figure
  3. I still get a TypeError

fepegar avatar May 26 '21 10:05 fepegar

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.

fepegar avatar May 26 '21 10:05 fepegar

Using the TkAgg backend, the viewer is shown, but

  1. The slices are black
  2. I can't close the figure
  3. 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.

Asterisci avatar May 26 '21 12:05 Asterisci

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.

fepegar avatar May 26 '21 12:05 fepegar