8000 Add bar color demo. by stefmolin · Pull Request #23670 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add bar color demo. #23670

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

Merged
merged 1 commit into from
Aug 19, 2022
Merged

Add bar color demo. #23670

merged 1 commit into from
Aug 19, 2022

Conversation

stefmolin
Copy link
Contributor

PR Summary

Adding a new bar plot example after #23525 to showcase the color and label arguments.

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • [N/A] Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@QuLogic QuLogic added this to the v3.6.0 milestone Aug 19, 2022
@stefmolin
Copy link
Contributor Author

@story645 - I know you initially mentioned having two examples, but I ended up making just one example to illustrate how label and color could be used, while also addressing how to hide a label. Let me know if you think we still need another example.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

ax.bar(fruits, counts, label=bar_labels, color=bar_colors)

ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')

plt.show()

Screen Shot 2022-08-18 at 8 58 54 PM

@story645
Copy link
Member
story645 commented Aug 19, 2022

I think the image is gonna read super well as a gallery thumbnail, so I love that. I am a little worried that it's doing a lot, but that's probably solvable in comments or w/ the simpler case added but this as the thumbnail.

ETA: or leave it be and if we get too many questions about the simpler case, add it then.

@QuLogic QuLogic merged commit 972e95c into matplotlib:main Aug 19, 2022
@story645
Copy link
Member

Also thanks so much @stefmolin for the new feature & for the new gallery entry 🥳

@stefmolin stefmolin deleted the new-bar-examples branch August 19, 2022 13:27
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.

3 participants
0