-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Allow for non-normalized and transformed markers #16773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Allow for custom marker scaling | ||
------------------------------- | ||
`~.markers.MarkerStyle` gained a keyword argument *normalization*, which may be | ||
set to *"none"* to allow for custom paths to not be scaled.:: | ||
|
||
MarkerStyle(Path(...), normalization="none") | ||
|
||
`~.markers.MarkerStyle` also gained a `~.markers.MarkerStyle.set_transform` | ||
method to set affine transformations to existing markers.:: | ||
|
||
m = MarkerStyle("d") | ||
m.set_transform(m.get_transform() + Affine2D().rotate_deg(30)) |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -201,7 +201,8 @@ class MarkerStyle: | |||||||||
# TODO: Is this ever used as a non-constant? | ||||||||||
_point_size_reduction = 0.5 | ||||||||||
|
||||||||||
def __init__(self, marker=None, fillstyle=None): | ||||||||||
def __init__(self, marker=None, fillstyle=None, *, | ||||||||||
normalization="classic"): | ||||||||||
""" | ||||||||||
Attributes | ||||||||||
---------- | ||||||||||
|
@@ -213,12 +214,23 @@ def __init__(self, marker=None, fillstyle=None): | |||||||||
|
||||||||||
Parameters | ||||||||||
---------- | ||||||||||
marker : str or array-like, optional, default: None | ||||||||||
marker : str, array-like, `~.path.Path`, or `~.markers.MarkerStyle`, \ | ||||||||||
default: None | ||||||||||
ImportanceOfBeingErnest marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
See the descriptions of possible markers in the module docstring. | ||||||||||
|
||||||||||
fillstyle : str, optional, default: 'full' | ||||||||||
'full', 'left", 'right', 'bottom', 'top', 'none' | ||||||||||
|
||||||||||
normalization : str, {'classic', 'none'}, optional, default: "classic" | ||||||||||
The normalization of the marker size. Only applies to custom paths | ||||||||||
that are provided as array of vertices or `~.path.Path`. | ||||||||||
Can take two values: | ||||||||||
*'classic'*, being the default, makes sure the marker path is | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be misreading this comment, but it seems like it's not that According to the discussion above. The docstring should read (if I understand correctly):
This is exactly the classic style, as far as I can tell. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hence the sentence "Only applies to custom paths...". So this is definitely correct. I'm happy to use a name other than "classic", but since I find that name fits pretty well, I would need input with alternative ideas. I guess this is also secondary compared to naming the argument itself - for which there is also no consensus yet it seems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear, I am 100% behind the "classic" name. I think it is consistently applied and fits well. I am also very happy with "normalization". However, wasn't one of the main benefits (and the impetus for this PR being revisited) that adding a "normalization" kwarg would allow us to address #15703? If so, I think that stating in the initial docstring that it only applies to custom paths (maybe just add "for now" if you don't like my more verbose wording). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm cautious to document any possible future behaviour. (We had some new normalization or the toolmanager being anounced as "coming soon" for years, which doesn't really help people using the library in the present.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100% onboard with not documenting "possible" future behavior. On the other hand, a wording closer to mine doesn't close the door to this feature (which is already implemented in my "paths" PR stack). Mostly just being selfish because I have a strong feeling that if the current phrasing of the docstring gets merged, I'll get pushback when I try to change it in my own PR, whereas an equally specific and correct version could be written that doesn't specify that this keyword "only applies to custom paths". As far as I'm concerned, feel free to merge this as-is and I'll just have that fight when it's time. |
||||||||||
normalized to fit within a unit-square by affine scaling. | ||||||||||
*'none'*, in which case no scaling is performed on the marker path. | ||||||||||
""" | ||||||||||
cbook._check_in_list(["classic", "none"], normalization=normalization) | ||||||||||
self._normalize = normalization | ||||||||||
self._marker_function = None | ||||||||||
self.set_fillstyle(fillstyle) | ||||||||||
self.set_marker(marker) | ||||||||||
|
@@ -303,6 +315,13 @@ def get_path(self): | |||||||||
def get_transform(self): | ||||||||||
return self._transform.frozen() | ||||||||||
|
||||||||||
def set_transform(self, transform): | ||||||||||
""" | ||||||||||
Sets the transform of the marker. This is the transform by which the | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First line of docstring should be separate.
Suggested change
|
||||||||||
marker path is transformed. | ||||||||||
""" | ||||||||||
self._transform = transform | ||||||||||
|
||||||||||
def get_alt_path(self): | ||||||||||
return self._alt_path | ||||||||||
|
||||||||||
|
@@ -316,8 +335,9 @@ def _set_nothing(self): | |||||||||
self._filled = False | ||||||||||
|
||||||||||
def _set_custom_marker(self, path): | ||||||||||
rescale = np.max(np.abs(path.vertices)) # max of x's and y's. | ||||||||||
self._transform = Affine2D().scale(0.5 / rescale) | ||||||||||
if self._normalize == "classic": | ||||||||||
rescale = np.max(np.abs(path.vertices)) # max of x's and y's. | ||||||||||
self._transform = Affine2D().scale(0.5 / rescale) | ||||||||||
self._path = path | ||||||||||
|
||||||||||
def _set_path_marker(self): | ||||||||||
|
@@ -350,8 +370,6 @@ def _set_tuple_marker(self): | |||||||||
def _set_mathtext_path(self): | ||||||||||
""" | ||||||||||
Draws mathtext markers '$...$' using TextPath object. | ||||||||||
|
||||||||||
Submitted by tcb | ||||||||||
""" | ||||||||||
from matplotlib.text import TextPath | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason this can't be a
transform=
kwarg? ietransform=None
would do what we did before...