-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Milestone
Description
This is the root cause of #16461. The single path optimisation does not correctly take into account offsets:
matplotlib/lib/matplotlib/collections.py
Lines 354 to 362 in acc7ecb
if do_single_path_optimization: | |
gc.set_foreground(tuple(edgecolors[0])) | |
gc.set_linewidth(self._linewidths[0]) | |
gc.set_dashes(*self._linestyles[0]) | |
gc.set_antialiased(self._antialiaseds[0]) | |
gc.set_url(self._urls[0]) | |
renderer.draw_markers( | |
gc, paths[0], combined_transform.frozen(), | |
mpath.Path(offsets), transOffset, tuple(facecolors[0])) |
As an example, this code creates two collections which differ only by their edgecolors
, and have an offset of [0.5, 0.5]
. In both cases the collection should be drawn at the offset, but only the collection with edgecolors=None
is correct, because this does not follow the 'optimised' code path above.
import matplotlib.pyplot as plt
import matplotlib.collections as mcoll
import matplotlib.transforms as mtransforms
import numpy as np
polygon = np.array([[-1, -1], [-1, 1], [1, 1], [1, -1]]) * 0.1
offsets = np.array([0.5, 0.5])
fig, axs = plt.subplots(ncols=2)
for ax, edgecolors in zip(axs, [None, 'face']):
collection = mcoll.PolyCollection(
[polygon],
edgecolors=edgecolors,
linewidths=[1],
offsets=offsets,
transOffset=mtransforms.IdentityTransform(),
offset_position="data"
)
ax.add_collection(collection)
plt.show()
Metadata
Metadata
Assignees
Labels
No labels