Skip to content

Commit

Permalink
horiz_bar fix (#37)
Browse files Browse the repository at this point in the history
* Add helper function for saving figure in multiple formats

* Return all axes from `horiz_bar`

* Bump patch version

* Change `axarr` to `axes`
  • Loading branch information
A-CGray authored Jul 11, 2023
1 parent cb1957d commit be76687
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/plot_bar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
2 changes: 1 addition & 1 deletion niceplots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.4.0"
__version__ = "2.4.1"

from .utils import *
from .parula import *
10 changes: 5 additions & 5 deletions niceplots/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit be76687

Please sign in to comment.