Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: AttributeError: 'Path3DCollection' object has no attribute '_offset_zordered' (possible regression) #26497

Copy link
Copy link
Closed
@varkappadev

Description

@varkappadev
Issue body actions

Bug summary

Adding a Line3DCollection to an animation results in Attribute error.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.collections import LineCollection
from mpl_toolkits.mplot3d.art3d import Line3DCollection
import numpy as np
import pkg_resources
import sys

lc = [(np.fromiter([0., 0., 0.], dtype="float"),
       np.fromiter([1., 1., 1.], dtype="float"))]
pc = [np.fromiter([0., 0.], dtype="float"), np.fromiter(
    [0., 1.], dtype="float"), np.fromiter([1., 1.], dtype="float")]

print(pkg_resources.get_distribution("matplotlib").version, file=sys.stderr)

fig = plt.figure()
ax = fig.add_subplot(projection="3d")
an = [[ax.add_collection(Line3DCollection(lc)),
       ax.scatter(*pc),
       ax.scatter(*pc),
       ],
      [ax.scatter(*pc),
       ax.scatter(*pc),
       ]
      ]
anim = animation.ArtistAnimation(fig, artists=an)
anim.save("mpl-test.webp", fps=100, writer="pillow")

Actual outcome

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/animation.py", line 233, in saving
    yield self
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/animation.py", line 1107, in save
    writer.grab_frame(**savefig_kwargs)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/animation.py", line 495, in grab_frame
    self.fig.savefig(
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/figure.py", line 3378, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 2366, in print_figure
    result = print_method(
             ^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 2232, in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
                                                                 ^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py", line 445, in print_raw
    FigureCanvasAgg.draw(self)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py", line 400, in draw
    self.figure.draw(self.renderer)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/figure.py", line 3175, in draw
    mimage._draw_list_compositing_images(
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 492, in draw
    super().draw(renderer)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/axes/_base.py", line 3064, in draw
    mimage._draw_list_compositing_images(
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/artist.py", line 39, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mpl_toolkits/mplot3d/art3d.py", line 643, in draw
    with self._use_zordered_offset():
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mpl_toolkits/mplot3d/art3d.py", line 758, in _use_zordered_offset
    if self._offset_zordered is None:
       ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Path3DCollection' object has no attribute '_offset_zordered'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/private/tmp/mpl-test.py", line 27, in <module>
    anim.save("mpl-test.webp", fps=100, writer="pillow")
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/animation.py", line 1085, in save
    with mpl.rc_context({'savefig.bbox': None}), \
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/animation.py", line 235, in saving
    self.finish()
  File "/opt/homebrew/lib/python3.11/site-packages/matplotlib/animation.py", line 501, in finish
    self._frames[0].save(
    ~~~~~~~~~~~~^^^
IndexError: list index out of range

Expected outcome

working animation

Additional information

Affected version: 3.7.2 (macos + homebrew + pip)
Unaffected: 3.6.3 (debian)

I am not sure if it is a backend or version issue. The problem also happens on mac with jupyter notebook and the notebook (inline and widget not tested) backend with my original (non-minimal) code.

Operating system

macos

Matplotlib Version

3.7.2

Matplotlib Backend

MacOSX

Python version

3.11.4

Jupyter version

7.0.2

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.