Skip to content

Legend shadow color #18668

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

Closed
wants to merge 15 commits into from
Closed

Legend shadow color #18668

wants to merge 15 commits into from

Conversation

Tranquilled
Copy link
Contributor

@Tranquilled Tranquilled commented Oct 6, 2020

PR Summary

Allows the shadow legend flag to be a color as well as a bool.
If it's a bool, the behavior is unchanged.

I'm unsure whether it would be best to apply the "shadow color transformation" to the specified color or leave it up to the user to decide.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and pydocstyle<4 and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@Tranquilled Tranquilled marked this pull request as ready for review October 6, 2020 03:59
@anntzer
Copy link
Contributor

anntzer commented Oct 6, 2020

Perhaps consider making shadow be True|False|color instead? (i.e. fold shadowcolor into shadow) This avoids e.g. having someone set shadowcolor and be puzzled that nothing happens when legend.shadow is actually False.

@Tranquilled
Copy link
Contributor Author

Perhaps consider making shadow be True|False|color instead? (i.e. fold shadowcolor into shadow) This avoids e.g. having someone set shadowcolor and be puzzled that nothing happens when legend.shadow is actually False.

Is this a pattern elsewhere? I did consider it, but didn't want to introduce a multiple-type flag if that's something that's not currently in the codebase.

@jklymak
Copy link
Member

jklymak commented Oct 6, 2020

We have lots of multiple type flags. And I agree with @anntzer that this would be an appropriate place for one.

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Would be great to have a test that passes a color for shadow.

@Tranquilled
Copy link
Contributor Author

Would be great to have a test that passes a color for shadow.

Do you know how those baseline_images files are generated?

@tacaswell
Copy link
Member

@Tranquilled Please see https://matplotlib.org/devel/testing.html#writing-an-image-comparison-test for instructions on how to add a new image test.

@tacaswell
Copy link
Member

however, if you can test that it worked (e.g. by inspecting the state of the Figuure) without adding a new image to the test suite that is preferred (to try and keep the size of the repository down).

@Tranquilled
Copy link
Contributor Author

however, if you can test that it worked (e.g. by inspecting the state of the Figuure) without adding a new image to the test suite that is preferred (to try and keep the size of the repository down).

Would it be valid to test the new if block by calling the shadow with the same color as default and seeing if it generates the same image? This keeps the repo size down but it seems like cheating.

@tacaswell
Copy link
Member

That would be a bit cheating. You might be able to do something to try and simulate a legend having a shadow and hijack your self into the draw order, but an image test with a 2x3 grid of default, True, False, {3 colors} maybe the best option here. You can probably use svg as the format which would be pretty small.

@Tranquilled
Copy link
Contributor Author

@tacaswell @dopplershift I can no longer tell why code coverage fails on this branch.

@timhoffm
Copy link
Member

timhoffm commented Nov 1, 2020

Don't worry about the coverage failuere, codecov sometimes does strange things.

@QuLogic
Copy link
Member

QuLogic commented Nov 3, 2020

Can you rebase to remove the reverted commits entirely?

Comment on lines +517 to +526
legends = {
'true': plt.legend(loc="upper left", shadow=True),
'false': plt.legend(loc="center left", shadow=False),
'default': plt.legend(loc="lower left"),
'colorstring': plt.legend(loc="upper right", shadow='red'),
'colortuple': plt.legend(loc="center right", shadow=(0.1, 0.2, 0.5)),
'colortab': plt.legend(loc="lower right", shadow='tab:cyan')
}
for x in legends:
plt.gca().add_artist(legends[x])
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this; doesn't plt.legend add the legend to the plot already? Also, use ax.legend instead.

@Tranquilled
Copy link
Contributor Author

@QuLogic If it's all the same to you I'd rather just squash.

ax.plot(range(100), label="test")
with pytest.raises(ValueError, match="color or bool"):
x = plt.legend(loc="upper left", shadow="aardvark")
fig.canvas.draw()
Copy link
Member

Choose a reason for hiding this comment

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

There's no need for this line, as the legend call would have raised.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think that's the case, the tests all fail.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't realize your checks are in draw; that's the wrong place. The setting should be validated in __init__ so that raising occurs when the legend is created, not at some random time in the future.

@QuLogic
Copy link
Member

QuLogic commented May 6, 2021

Ping? Tests are not passing, and there are file conflicts.

@jklymak jklymak marked this pull request as draft May 8, 2021 22:08
@Tranquilled Tranquilled closed this by deleting the head repository Dec 8, 2022
@tuncbkose tuncbkose mentioned this pull request Dec 8, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants