Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
secondary_yand then plotting another line results in wrong color for (right) line #40044I spent several hours on this, and I don't think there's a simple solution at the moment (though I'd love to be proved wrong!)
Background:
in Nov 2017, #18222 was opened, in which it was noted that marker info isn't preserved in legends. This is because we were getting legend handles using
leg.legendHandles:pandas/pandas/plotting/_matplotlib/core.py
Line 574 in b623a9d
Due to an open issue in matplotlib,
leg.legendHandlesdoesn't preserve marker info. So, in #27808, the code was updated to useax.get_legend_handles_labels:pandas/pandas/plotting/_matplotlib/core.py
Line 604 in 5d3b492
This preserves marker info but has the problem that it may contain additional objects which aren't visible in the legend. The result of this is the permutations observed in #39522 .
I think that having wrong colours in the legend, as in #39522 and #40044, is far worse than the legend not preserving marker info. Solving everything together doesn't currently seem doable, at least not until matplotlib/matplotlib#11357 is solved in matplotlib.
So my suggestion is to revert some of the changes in #27808, so that at least the colors are right, and when the matplotlib issue is addressed, then the marker info can be preserved.
#39522 on master:
on this branch:
#40044 on master:
on this branch: