FIX: Only render single patch for scatter#7214
Conversation
NelleV
left a comment
There was a problem hiding this comment.
There are parts of matplotlib I just don't understand…
Sorry, my review isn't very useful: I am just trying to understand what's going on: I don't see how your patch is fixing the bug.
| @@ -316,7 +316,7 @@ def get_sizes(self, legend, orig_handle, | |||
| numpoints = self.get_numpoints(legend) | |||
| if numpoints < 4: | |||
| sizes = [.5 * (size_max + size_min), size_max, | |||
There was a problem hiding this comment.
That could easily be unit tested.
There was a problem hiding this comment.
It is possible that this is the only change that really matters here.
There was a problem hiding this comment.
all the more reason to unit test it, no?
It is a very easy unit test to check that the return lengths is equal to numpoints.
Also, my two cents is that I would much prefer the returned size to be sorted (only matters for numpoints == 3)
There was a problem hiding this comment.
I also vote for drawing the markers in increasing size. (This also makes the code simpler; now only numpoints=1 needs to be special-cased.)
lib/matplotlib/backend_bases.py
Outdated
| return 0 | ||
| Npath_ids = max(Npaths, len(all_transforms)) | ||
| N = max(Npath_ids, len(offsets)) | ||
| N = max(Npaths, len(offsets)) |
There was a problem hiding this comment.
If I am not mistaken, this function is only used to compute whether or not to do an optimization. Hence, over estimating the number of paths drawn is not that important and I am assuming that this as no impact on the bug you are fixing?
There was a problem hiding this comment.
(Also, if we put a fix there, I'd also just replace the next line by return int(np.ceil(N / Npath_ids)) which is much clearer in intent.)
There was a problem hiding this comment.
Is this even needed to fix the problem?
There was a problem hiding this comment.
It's just an optimization (see docstring) and it doesn't even really matter whether this is correct or not (modulo an unnecessary increase in the size of the svg).
|
The difference in the test_legend png baseline plots is imperceptible by eye. Perhaps it would be worthwhile to modify that test to include the alpha and size variation from the scatter example that showed the problem in the first place. |
|
@NelleV I figured it out: that's because I used |
|
Interesting. Maybe the code should raise a warning? |
|
@NelleV that's a bit a side issue but anyways... Currently (resulting plot is empty). If anything this should raise a ValueError (and whether to error on zero sizes or not is a separate issue). |
2830f11 to
524cfbd
Compare
|
The failure seems unrelated, but is consistently here… |
|
.... and only on pytest. When in doubt |
524cfbd to
25fbe8f
Compare
|
Thanks @tacaswell ! |
FIX: Only render single patch for scatter
|
backported to v2.x as 568b523 |
Alternative to #6883