diff --git a/qiskit/visualization/counts_visualization.py b/qiskit/visualization/counts_visualization.py index 546a027b5b79..6d93ff6bfac0 100644 --- a/qiskit/visualization/counts_visualization.py +++ b/qiskit/visualization/counts_visualization.py @@ -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", @@ -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] @@ -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: @@ -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) @@ -404,7 +402,6 @@ def _plotting_core( ncol=1, borderaxespad=0, frameon=True, - fontsize=12, ) if fig: matplotlib_close_if_inline(fig) diff --git a/releasenotes/notes/histogram-style-03807965c3cc2e8a.yaml b/releasenotes/notes/histogram-style-03807965c3cc2e8a.yaml new file mode 100644 index 000000000000..5904885c430b --- /dev/null +++ b/releasenotes/notes/histogram-style-03807965c3cc2e8a.yaml @@ -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. diff --git a/test/visual/mpl/graph/references/histogram.png b/test/visual/mpl/graph/references/histogram.png index 1d11b0d110ce..3fa51ec644ed 100644 Binary files a/test/visual/mpl/graph/references/histogram.png and b/test/visual/mpl/graph/references/histogram.png differ diff --git a/test/visual/mpl/graph/references/histogram_2_sets_with_rest.png b/test/visual/mpl/graph/references/histogram_2_sets_with_rest.png index ab02566c1561..fe11f5811931 100644 Binary files a/test/visual/mpl/graph/references/histogram_2_sets_with_rest.png and b/test/visual/mpl/graph/references/histogram_2_sets_with_rest.png differ diff --git a/test/visual/mpl/graph/references/histogram_color.png b/test/visual/mpl/graph/references/histogram_color.png index 48890f468c7f..34f7d449616a 100644 Binary files a/test/visual/mpl/graph/references/histogram_color.png and b/test/visual/mpl/graph/references/histogram_color.png differ diff --git a/test/visual/mpl/graph/references/histogram_desc_value_sort.png b/test/visual/mpl/graph/references/histogram_desc_value_sort.png index 4a963ff40212..b119ae2deed4 100644 Binary files a/test/visual/mpl/graph/references/histogram_desc_value_sort.png and b/test/visual/mpl/graph/references/histogram_desc_value_sort.png differ diff --git a/test/visual/mpl/graph/references/histogram_hamming.png b/test/visual/mpl/graph/references/histogram_hamming.png index 12ed9e6418e2..95bfe0ab1049 100644 Binary files a/test/visual/mpl/graph/references/histogram_hamming.png and b/test/visual/mpl/graph/references/histogram_hamming.png differ diff --git a/test/visual/mpl/graph/references/histogram_legend.png b/test/visual/mpl/graph/references/histogram_legend.png index daa61cdeeb43..77fbe9c5dc0f 100644 Binary files a/test/visual/mpl/graph/references/histogram_legend.png and b/test/visual/mpl/graph/references/histogram_legend.png differ diff --git a/test/visual/mpl/graph/references/histogram_multiple_colors.png b/test/visual/mpl/graph/references/histogram_multiple_colors.png index c1ecd9aef02e..7edbfc07bab5 100644 Binary files a/test/visual/mpl/graph/references/histogram_multiple_colors.png and b/test/visual/mpl/graph/references/histogram_multiple_colors.png differ diff --git a/test/visual/mpl/graph/references/histogram_title.png b/test/visual/mpl/graph/references/histogram_title.png index cf72f4181c12..c4c6859c8f2e 100644 Binary files a/test/visual/mpl/graph/references/histogram_title.png and b/test/visual/mpl/graph/references/histogram_title.png differ diff --git a/test/visual/mpl/graph/references/histogram_value_sort.png b/test/visual/mpl/graph/references/histogram_value_sort.png index df5328ef884c..e44d08e0d9f9 100644 Binary files a/test/visual/mpl/graph/references/histogram_value_sort.png and b/test/visual/mpl/graph/references/histogram_value_sort.png differ diff --git a/test/visual/mpl/graph/references/histogram_with_rest.png b/test/visual/mpl/graph/references/histogram_with_rest.png index baecf1b96bd4..69633c1e4fdb 100644 Binary files a/test/visual/mpl/graph/references/histogram_with_rest.png and b/test/visual/mpl/graph/references/histogram_with_rest.png differ