matplotlib icon indicating copy to clipboard operation
matplotlib copied to clipboard

[Bug]: `add_collection3d` does not update view limits

Open Qrox opened this issue 3 years ago • 2 comments

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

Qrox avatar Jun 21 '22 10:06 Qrox

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.

Qrox avatar Jun 27 '22 12:06 Qrox

I guess it may be possible to iterate over the collection objects similar to https://github.com/matplotlib/matplotlib/blob/4f5cacfde9024076d9ab0cb6ad1c9a7cf352d5f9/lib/matplotlib/axes/_base.py#L2453-L2460

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

oscargus avatar Aug 08 '22 10:08 oscargus