Skip to content

Commit

Permalink
Remove hardcoded styling in plot_histogram (Qiskit#8761)
Browse files Browse the repository at this point in the history
* Remove hardcoded styling in plot_histogram

* black

* Add release note

* update ref images

* Update releasenotes/notes/histogram-style-03807965c3cc2e8a.yaml

Co-authored-by: Luciano Bello <[email protected]>

* Update qiskit/visualization/counts_visualization.py

---------

Co-authored-by: Luciano Bello <[email protected]>
  • Loading branch information
nonhermitian and 1ucian0 authored Apr 4, 2024
1 parent f76f692 commit 03eb77a
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 6 deletions.
9 changes: 3 additions & 6 deletions qiskit/visualization/counts_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _is_deprecated_data_format(data) -> bool:

def plot_histogram(
data,
figsize=(7, 5),
figsize=None,
color=None,
number_to_keep=None,
sort="asc",
Expand Down Expand Up @@ -296,7 +296,7 @@ def _plotting_core(

# Set bar colors
if color is None:
color = ["#648fff", "#dc267f", "#785ef0", "#ffb000", "#fe6100"]
color = plt.rcParams["axes.prop_cycle"].by_key()["color"]
elif isinstance(color, str):
color = [color]

Expand Down Expand Up @@ -350,7 +350,7 @@ def _plotting_core(
label = None
bar_center = (width / 2) * (length - 1)
ax.set_xticks(all_inds[item] + bar_center)
ax.set_xticklabels(labels_dict.keys(), fontsize=14, rotation=70)
ax.set_xticklabels(labels_dict.keys(), rotation=70, ha="right", rotation_mode="anchor")
# attach some text labels
if bar_labels:
for rect in rects:
Expand Down Expand Up @@ -391,8 +391,6 @@ def _plotting_core(
ax.invert_xaxis()

ax.yaxis.set_major_locator(MaxNLocator(5))
for tick in ax.yaxis.get_major_ticks():
tick.label1.set_fontsize(14)
plt.grid(which="major", axis="y", zorder=0, linestyle="--")
if title:
plt.title(title)
Expand All @@ -404,7 +402,6 @@ def _plotting_core(
ncol=1,
borderaxespad=0,
frameon=True,
fontsize=12,
)
if fig:
matplotlib_close_if_inline(fig)
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/histogram-style-03807965c3cc2e8a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
upgrade:
- |
Removes the hard-coding of style options for :func:`~.plot_histogram`. This allows
Matplotlib style files to be faithfully applied to the figures. Users looking to go
beyond the defaults set by Matplotlib can make their own style files, or pass a
Matplotlib ``Axes`` object to ``plot_histogram`` and post-apply any customizations.
Binary file modified test/visual/mpl/graph/references/histogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_2_sets_with_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_desc_value_sort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_hamming.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_legend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_multiple_colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_value_sort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/visual/mpl/graph/references/histogram_with_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 03eb77a

Please sign in to comment.