Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AttributeError raised in OrthoSlicer3D #920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fepegar opened this issue Jun 4, 2020 · 12 comments
Open

AttributeError raised in OrthoSlicer3D #920

fepegar opened this issue Jun 4, 2020 · 12 comments

Comments

@fepegar
Copy link
Contributor

fepegar commented Jun 4, 2020

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
@effigies
Copy link
Member

effigies commented Jun 4, 2020

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

@fepegar
Copy link
Contributor Author

fepegar commented Jun 4, 2020

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
Copy link
Contributor Author

fepegar commented Jun 5, 2020

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

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

@effigies
Copy link
Member

effigies commented Aug 2, 2020

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

@effigies effigies closed this as completed Aug 2, 2020
@effigies
Copy link
Member

effigies commented Aug 2, 2020

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

@effigies effigies reopened this Aug 2, 2020
@fepegar
Copy link
Contributor Author

fepegar commented Aug 2, 2020

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

@0xSMT
Copy link

0xSMT commented Jan 22, 2021

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

@Asterisci
Copy link

Asterisci commented May 25, 2021

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

@fepegar
Copy link
Contributor Author

fepegar commented May 26, 2021

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
Copy link
Contributor Author

fepegar commented May 26, 2021

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.

@Asterisci
Copy link

Asterisci commented May 26, 2021

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.

@fepegar
Copy link
Contributor Author

fepegar commented May 26, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants