From be7668702eaf95ea07dabf2a605930547286eccf Mon Sep 17 00:00:00 2001 From: Alasdair Gray Date: Tue, 11 Jul 2023 13:57:50 -0700 Subject: [PATCH] `horiz_bar` fix (#37) * Add helper function for saving figure in multiple formats * Return all axes from `horiz_bar` * Bump patch version * Change `axarr` to `axes` --- examples/plot_bar_chart.py | 2 +- niceplots/__init__.py | 2 +- niceplots/utils.py | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/plot_bar_chart.py b/examples/plot_bar_chart.py index 9c6bf52..c0ef8b5 100644 --- a/examples/plot_bar_chart.py +++ b/examples/plot_bar_chart.py @@ -19,5 +19,5 @@ nd = 4 with plt.style.context(niceplots.get_style()): - fig, ax = niceplots.horiz_bar(labels, times, header, nd=nd, size=[7, 0.65]) + fig, axes = niceplots.horiz_bar(labels, times, header, nd=nd, size=[7, 0.65]) niceplots.save_figs(fig, "bar_chart", ["png", "svg"]) diff --git a/niceplots/__init__.py b/niceplots/__init__.py index 7379a9d..2b89059 100644 --- a/niceplots/__init__.py +++ b/niceplots/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.4.0" +__version__ = "2.4.1" from .utils import * from .parula import * diff --git a/niceplots/utils.py b/niceplots/utils.py index b23ce38..ef27211 100644 --- a/niceplots/utils.py +++ b/niceplots/utils.py @@ -339,8 +339,8 @@ def horiz_bar(labels, times, header, nd=1, size=[5, 0.5], color=None): ------- fig: matplotlib Figure Figure created - ax: matplotlib Axes - Axes on which data is plotted + axes: array of matplotlib Axes + The subplot axes, one for each bar """ # Use the first color if none is specified @@ -356,7 +356,7 @@ def horiz_bar(labels, times, header, nd=1, size=[5, 0.5], color=None): t_max = max(times) # Create the corresponding number of subplots for each individual timing - fig, axarr = plt.subplots(num, 1, figsize=[width, height]) + fig, axes = plt.subplots(num, 1, figsize=[width, height]) # Loop over each time and get the max number of digits t_max_digits = 0 @@ -366,7 +366,7 @@ def horiz_bar(labels, times, header, nd=1, size=[5, 0.5], color=None): t_max_digits = tm # Actual loop that draws each bar - for j, (l, t, ax) in enumerate(zip(labels, times, axarr)): + for j, (l, t, ax) in enumerate(zip(labels, times, axes)): # Draw the gray line and singular yellow dot ax.axhline(y=1, c=line_color, lw=3, zorder=0, alpha=0.5) ax.scatter([t], [1], c=color, lw=0, s=100, zorder=1, clip_on=False) @@ -405,7 +405,7 @@ def horiz_bar(labels, times, header, nd=1, size=[5, 0.5], color=None): ax.text(0, 1.02, header[0], ha="right", fontweight="bold", fontsize="large") ax.text(t_max, 1.02, header[1], ha="left", fontweight="bold", fontsize="large") - return fig, ax + return fig, axes def stacked_plots(