Skip to content

[Bug]: add_collection3d does not update view limits #23317

Closed

Description

@Qrox

Bug summary

When creating a 3D plot using add_collection3d, the view limits are not automatically updated like in other plot functions.

Possibly related to #14298.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.collections
import numpy as np

fig, ax = plt.subplots(1, 1, figsize=(7, 4), constrained_layout=True, subplot_kw=dict(projection='3d', proj_type='ortho'))
xy = np.array([[(0, 0), (0.5, 100), (1, 0)]])
ax.add_collection3d(matplotlib.collections.LineCollection(xy))
# Manually update view limits
# ax.auto_scale_xyz(xy[..., 0], xy[..., 1], None, ax.has_data())
plt.show()

Actual outcome

image

Expected outcome

Produced by uncommenting the line of code below # Manually update view limits.

image

Additional information

I'm using matplotlib 3.5.0, but the relevant code does not seem to call auto_scale_xyz like the other plot functions in the 3.5.2 branch or the main branch.

Operating system

Window 10

Matplotlib Version

3.5.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.9.9

Jupyter version

3.4.3

Installation

pip

Activity

  1. Qrox commented on Jun 27, 2022

    @Qrox
    Author

    On further test this seems to also happen with add_collection of 2D plots and seems to be known to be broken judging from the documentation for matplotlib.axes.Axes.relim.

    Recompute the data limits based on current artists.
    At present, Collection instances are not supported.

    Anyway, it is still best to make this consistent with the other plotting functions.

  2. oscargus commented on Aug 8, 2022

    @oscargus
    Member

    I guess it may be possible to iterate over the collection objects similar to

    for artist in self._children:
    if not visible_only or artist.get_visible():
    if isinstance(artist, mlines.Line2D):
    self._update_line_limits(artist)
    elif isinstance(artist, mpatches.Patch):
    self._update_patch_limits(artist)
    elif isinstance(artist, mimage.AxesImage):
    self._update_image_limits(artist)

    but there may be some obstacles (including being slow for large collections...).

  3. added this to the v3.9.1 milestone on Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions