Fix marker fillstyle rotation transform#31301
Fix marker fillstyle rotation transform#31301jayaprajapatii wants to merge 3 commits intomatplotlib:mainfrom
Conversation
lib/matplotlib/lines.py
Outdated
| if not isinstance(marker, MarkerStyle): | ||
| marker = MarkerStyle(marker) |
There was a problem hiding this comment.
What can marker be apart of MarkerStyle. I suspect we should rather coerce self._marker to always be a MarkerStyle right away instead of doing a conversion here.
lib/matplotlib/markers.py
Outdated
| new = cls(marker=marker, fillstyle=fillstyle) | ||
|
|
||
| new._user_transform = other._user_transform | ||
| new._joinstyle = other._joinstyle | ||
| new._capstyle = other._capstyle | ||
| new._snap_threshold = other._snap_threshold |
There was a problem hiding this comment.
Explicitly copying selected values puts us in dager of forgetting something.
Please check: Is it reasonable to copy the whole other.__dict__ and then replace the required attrs? This among other things depends on whether the attributes are independent of each other.
timhoffm
left a comment
There was a problem hiding this comment.
Please also answer the questions in the two comments from previous reviews, that I have not marked as resolved.
lib/matplotlib/lines.py
Outdated
| from matplotlib.markers import MarkerStyle | ||
|
|
There was a problem hiding this comment.
Imports must be placed at the top, not somewhere in the middle of the file. Also, the import is already there.
| from matplotlib.markers import MarkerStyle |
| from matplotlib.transforms import Affine2D | ||
|
|
||
| import pytest | ||
| from matplotlib.markers import MarkerStyle |
There was a problem hiding this comment.
Please ensure a consistent use throughout the module; i.e. don't mix markers.MarkerStyle and MarkerStyle.
|
Hello @timhoffm I explored approaches using Happy to revise if you'd prefer a different approach. |
Closes #31257
Problem
Updating the fillstyle of a marker using
Line2D.set_fillstyle()recreates the marker usingMarkerStyle(self._marker.get_marker(), fs). This drops existing attributes stored in the originalMarkerStyle, including the rotation transform. As a result, rotated markers lose their rotation after updating the fillstyle.Cause
set_fillstyle()constructs a newMarkerStylefrom the marker symbol. This discards internal attributes such as the transform that were present in the originalMarkerStyleinstance.Solution
Use the
MarkerStyle._with_attrs()factory method to construct the updated marker while preserving the attributes of the existing marker.This ensures that properties such as transform, joinstyle, and capstyle remain unchanged when updating the fillstyle.
Changes
Line2D.set_fillstyle()to useMarkerStyle._with_attrs()instead of constructing a newMarkerStyle.Result
Rotated markers now maintain their rotation when
set_fillstyle()is called, matching the expected behaviour described in the issue.