Skip to content
  • Sponsor matplotlib/matplotlib

  • Notifications You must be signed in to change notification settings
  • Fork 8k
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
@@ -2182,11 +2182,19 @@ def _convert_dx(dx, x0, xconv, convert):
x0 = cbook._safe_first_finite(x0)
except (TypeError, IndexError, KeyError):
pass
except StopIteration:
# this means we found no finite element, fall back to first
# element unconditionally
x0 = cbook.safe_first_element(x0)

try:
x = cbook._safe_first_finite(xconv)
except (TypeError, IndexError, KeyError):
x = xconv
except StopIteration:
# this means we found no finite element, fall back to first
# element unconditionally
x = cbook.safe_first_element(xconv)

delist = False
if not np.iterable(dx):
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
@@ -8144,3 +8144,16 @@ def test_bar_leading_nan():
for b in rest:
assert np.isfinite(b.xy).all()
assert np.isfinite(b.get_width())


@check_figures_equal(extensions=["png"])
def test_bar_all_nan(fig_test, fig_ref):
mpl.style.use("mpl20")
ax_test = fig_test.subplots()
ax_ref = fig_ref.subplots()

ax_test.bar([np.nan], [np.nan])
ax_test.bar([1], [1])

ax_ref.bar([1], [1]).remove()
ax_ref.bar([1], [1])