Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix legend color comparisions#10031

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 3 commits intomatplotlib:masterfromdstansby:legend-colors
Dec 20, 2017
Merged

Conversation

dstansby
Copy link
Member

@dstansbydstansby commentedDec 17, 2017
edited
Loading

Alternative to#10030 - Matplotlib colors can be lots of different types, so convert them to rgba arrays before comparing.

skirpichevand others added2 commitsDecember 17, 2017 14:07
This code was introduced in v2.1.1 and, apparently, wasn't tested, because .get_color() returns array.Here is an issue example:sympy/sympy#13730 (comment)
@jklymak
Copy link
Member

Given that we had bug reports when this as changed, yet the changes passed all the tests, either the tests are incomplete or this is accommodating undocumented use of colours. Can we add a test and or document whatever this is supposed to fix?

@dstansby
Copy link
MemberAuthor

dstansby commentedDec 17, 2017
edited
Loading

The problem is the original 'color comparison' code in the figure legend method didn't allow for colors to be numpy arrays. Long term I think this should be avoided by a general function for comparing colors, which I've put in#10032

@jklymak
Copy link
Member

Yeah, the problem is that this code didn'tchange in 2.1.1, it just got applied toFigure.legend() as well asaxes.legend(). So we broke things by making them more consistent. But I'm still not understanding the use-case.

If in master I do

importmatplotlib.pyplotaspltimportnumpyasnpfig,ax=plt.subplots()ax.plot(np.arange(10),color=np.array([0.1,0.3,0.4]),label='boo')fig.legend()plt.show()

That works fine. So 1-D numpy arrays work OK in master.

The error comes when the user specifies a 2-D array

importmatplotlib.pyplotaspltimportnumpyasnpfig,ax=plt.subplots()ax.plot(np.arange(10),color=np.array([[0.1,0.3,0.4]]),label='boo')fig.legend()plt.show()
ValueError: Invalid RGBA argument: array([[ 0.1,  0.3,  0.4]])

I'd argue specifying a 2-D array is not correct, and if it worked before, that was just a fortunate happenstance. OTOH,plot lets you put a 2-D array in, so I agree legend should as well.

Anyway, upshot is we should add a test to test for 2-D arrays being allowed.

@jklymak
Copy link
Member

jklymak commentedDec 17, 2017
edited
Loading

OK, I take it back; the above 2-D array test fails in 2.1.0 and 2.0.2 as well. So I'm not clear what the failure case is here. What color spec failed in 2.1.1 that this fixes?

ping@skirpichev

@skirpichev
Copy link
Contributor

@jklymak, sorry. I can't provide better failing test yet.

@jklymak
Copy link
Member

OK< let us know.

I can reproduce

ValueError: Invalid RGBA argument: array([[ 0.12156863,  0.46666667,  0.70588235,  1.        ]])

but I get that all the way back to 2.0.2, so I don't think this every worked?

If you could just print c before its passed to legend, that would help clarify things.

@dstansby's fix above seems to work for you, but the minimal test I put in abovedoesn't work on@dstansby's change. So I am mystified. Most importantly we should make sure we have a test that covers your case and the case that is breaking forsympy/sympy#13730

@skirpichev
Copy link
Contributor

Most importantly we should make sure we have a test that covers your case and the case that is breaking forsympy/sympy#13730

Probably, these testcases should be same, as Diofant and Sympy share some codebase.

@tacaswelltacaswell added this to thev2.1.2 milestoneDec 18, 2017
Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Lets hold of merging for a few days to let@skirpichev / the sympy folks to track down a test case.

@jklymak
Copy link
Member

See here for a link to their efforts:sympy/sympy#13730 (comment)

@jklymak
Copy link
Member

I'll put in a TST PR for this.

@dstansbydstansby deleted the legend-colors branchDecember 20, 2017 21:08
QuLogic added a commit that referenced this pull requestDec 21, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v2.1.2
Development

Successfully merging this pull request may close these issues.

4 participants
@dstansby@jklymak@skirpichev@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp