Skip to content
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

Remove hardcoded styling in plot_histogram #8761

Merged
merged 8 commits into from
Apr 4, 2024

Conversation

nonhermitian
Copy link
Contributor

Summary

plot_histogram was hardcoding things like bar colors, font and figure sizes, etc, that were preventing Matplotlib style files from being faithfully applied to the images.

Here we remove the hardcoded values, allowing complete customization following the loaded stylelib. Users wishing to modify the default settings further can either make their own styles, or take advantage of the fact that one can pass an Axes object, giving complete control of the customization post-generation.

Details and comments

The bar colors are now sourced from the rcParams which are in turn set by the style. Most hard-coded options have been removed save for the rotation of the x-axis labels that need to be rotated. I have also disabled bar_labels by default as for anything more than 2-3Q, the labels are unreadable, and unnecessary given the y-axis is also labeled and the data is included in the Counts themselves.

This allows one to make figures that look like:

image

or

image

easily

@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

@nonhermitian
Copy link
Contributor Author

This should wait for #8762 to be merged so that I can refactor on top of those changes.

@HuangJunye HuangJunye added the mod: visualization qiskit.visualization label Sep 19, 2022
@nonhermitian nonhermitian added the on hold Can not fix yet label Sep 28, 2022
@nonhermitian nonhermitian removed the on hold Can not fix yet label Aug 18, 2023
Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this PR. The feature makes sense to me. Just a small comment on bar_labels that I dont get.

releasenotes/notes/histogram-style-03807965c3cc2e8a.yaml Outdated Show resolved Hide resolved
qiskit/visualization/counts_visualization.py Outdated Show resolved Hide resolved
@1ucian0 1ucian0 self-assigned this Dec 13, 2023
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
@1ucian0 1ucian0 added this to the 1.0.0 milestone Jan 15, 2024
@mtreinish mtreinish modified the milestones: 1.0.0, 1.1.0 Jan 29, 2024
@1ucian0 1ucian0 enabled auto-merge April 4, 2024 15:02
@1ucian0 1ucian0 added Changelog: New Feature Include in the "Added" section of the changelog Changelog: None Do not include in changelog and removed Changelog: New Feature Include in the "Added" section of the changelog labels Apr 4, 2024
@1ucian0 1ucian0 added this pull request to the merge queue Apr 4, 2024
Merged via the queue into Qiskit:main with commit 03eb77a Apr 4, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: visualization qiskit.visualization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants