-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
POC: make scaling optional in Collection.get_linestyle #29304
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
base: main
Are you sure you want to change the base?
Conversation
d8f3119
to
1eed1a3
Compare
@@ -626,6 +626,11 @@ def set_linestyle(self, ls): | |||
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a | |||
complete description. | |||
""" | |||
if isinstance(ls, (str, tuple)): | |||
self._original_linestyle = [ls] |
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.
I got a lot more failures if I did not make sure this is a list. I note that Collection.get_facecolor
always returns a sequence of colours, having applied to_rgba_array
.
It may make sense to make this part of a general consolidation of
It seem we do most of this for the different artists #29302 (comment). I haven't thought too deep, but don't see a clear winner. There are pros and cons for all of them. So it might be an option the add a more general Thoughts welcome. |
I would vote for either getting back what you put in or normalising to unscaled dash pattern. I can’t see the value of normalising to a string because you lose information. The OPs of #23437 and #17316 object to the current Line2D behaviour. Also #23056 (comment). Normalising to the dash pattern would seem consistent with the fact that colours normalise to RGBA. Presumably it gives some efficiency saving when it is copied across to another object such as a legend handle, as you do not need to translate to the pattern on the new artist. Of course normalising to unscaled dash pattern is the one that we’re not currently doing anywhere 😄 |
1eed1a3
to
d7513a7
Compare
This sounds reasonable, and I'd be in favor of normalizing to a canonical representation. However, I'm not clear that the dash pattern is such a canonical representation in the same way RGBA is for color
An alternative would be normalizing to
Likely 'solid' and 'none' need special checks and code paths anyway, so there's not really a benefit in trying to express a line style without dashes as a formal dash pattern. |
This seems like it might be related to #23056, whose discussion never really finished. |
Inspired by but independent of the discussion around the representation of linestyles matplotlib#29304. For other linestyles we have a short visual representation (e.g. "--") and a name (dashed "dashed"). No linestyle currently has four accepted writings "", " ", "none", "None". This PR recommends only to use "" (visual representation) and "none" (named representation). It discourages " " and "None". This should guide users towards more canonical usage. We may later decide whether to deprecate the alternatives. Note also, that we have not used the alternatives in examples.
Inspired by but independent of the discussion around the representation of linestyles matplotlib#29304. For other linestyles we have a short visual representation (e.g. "--") and a name (dashed "dashed"). No linestyle currently has four accepted writings "", " ", "none", "None". This PR recommends only to use "" (visual representation) and "none" (named representation). It discourages " " and "None". This should guide users towards more canonical usage. We may later decide whether to deprecate the alternatives. Note also, that we have not used the alternatives in examples.
It's all quite a mess. Fundamentally, I believe we need to decide:
I suggest we discuss these on a green field ("What would be a good design") and only afterwards see how we can migrate there. |
FYI that there is this old PR suggesting to make a LineStyle class: #18664 |
I think we've moved away from necessarily wanting classes for all conecptual types. One of the main arguments was a concise definition of what values are accepted. We can now encode this using the typing system. That's not to say classes are completely off the table. If there's enough related functionality a class is still an option (e.g. the existing |
Inspired by but independent of the discussion around the representation of linestyles matplotlib#29304. For other linestyles we have a short visual representation (e.g. "--") and a name (dashed "dashed"). No linestyle currently has four accepted writings "", " ", "none", "None". This PR recommends only to use "" (visual representation) and "none" (named representation). It discourages " " and "None". This should guide users towards more canonical usage. We may later decide whether to deprecate the alternatives. Note also, that we have not used the alternatives in examples.
PR summary
Currently
Collection.get_linestyle()
returns the scaled dash pattern, i.e. the pattern multiplied by the linewidth. This is inconsistent with the equivalent method onLine2D
andPatch
(#17316 (comment)). This PR introduces the scaled parameter, to make this behaviour optional. For now I have set the default toFalse
to demonstrate that very little seems to be relying on the current scaled behaviour. Obviously we would need a deprecation period before we can do that for real.As shown by the new test, this allows us to fix the case noted at #28298 (comment). It does not fix the original case from that issue as we just move the error to here:
matplotlib/lib/matplotlib/patches.py
Line 603 in a23ef5a
So I think we need some version of #29302 for that case.
PR checklist