Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab4eeda

Browse filesBrowse files
committed
Merge pull request #5239 from tacaswell/fix_bar_labels
Fix bar labels
2 parents 2d9aa73 + cbad5d7 commit ab4eeda
Copy full SHA for ab4eeda

File tree

Expand file treeCollapse file tree

2 files changed

+21
-16
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-16
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+14-16Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from matplotlib import unpack_labeled_data
1515

1616
import matplotlib.cbook as cbook
17-
from matplotlib.cbook import mplDeprecation, STEP_LOOKUP_MAP
17+
from matplotlib.cbook import (mplDeprecation, STEP_LOOKUP_MAP,
18+
iterable, is_string_like)
1819
import matplotlib.collections as mcoll
1920
import matplotlib.colors as mcolors
2021
import matplotlib.contour as mcontour
@@ -43,10 +44,6 @@
4344

4445
rcParams = matplotlib.rcParams
4546

46-
iterable = cbook.iterable
47-
is_string_like = cbook.is_string_like
48-
is_sequence_of_strings = cbook.is_sequence_of_strings
49-
5047

5148
def _plot_args_replacer(args, data):
5249
if len(args) == 1:
@@ -1983,9 +1980,6 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
19831980
edgecolor = kwargs.pop('edgecolor', None)
19841981
linewidth = kwargs.pop('linewidth', None)
19851982

1986-
tick_label = kwargs.pop('tick_label', None)
1987-
label_ticks_flag = tick_label is not None
1988-
19891983
# Because xerr and yerr will be passed to errorbar,
19901984
# most dimension checking and processing will be left
19911985
# to the errorbar method.
@@ -2001,6 +1995,7 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
20011995
orientation = kwargs.pop('orientation', 'vertical')
20021996
log = kwargs.pop('log', False)
20031997
label = kwargs.pop('label', '')
1998+
tick_labels = kwargs.pop('tick_label', None)
20041999

20052000
def make_iterable(x):
20062001
if not iterable(x):
@@ -2016,7 +2011,6 @@ def make_iterable(x):
20162011
_bottom = bottom
20172012
bottom = make_iterable(bottom)
20182013
linewidth = make_iterable(linewidth)
2019-
tick_label = make_iterable(tick_label)
20202014

20212015
adjust_ylim = False
20222016
adjust_xlim = False
@@ -2061,8 +2055,6 @@ def make_iterable(x):
20612055

20622056
if len(linewidth) < nbars:
20632057
linewidth *= nbars
2064-
if len(tick_label) < nbars:
2065-
tick_label *= nbars
20662058

20672059
if color is None:
20682060
color = [None] * nbars
@@ -2095,9 +2087,6 @@ def make_iterable(x):
20952087
if len(bottom) != nbars:
20962088
raise ValueError("incompatible sizes: argument 'bottom' "
20972089
"must be length %d or scalar" % nbars)
2098-
if len(tick_label) != nbars:
2099-
raise ValueError("incompatible sizes: argument 'tick_label' "
2100-
"must be length %d or string" % nbars)
21012090

21022091
patches = []
21032092

@@ -2193,9 +2182,18 @@ def make_iterable(x):
21932182
bar_container = BarContainer(patches, errorbar, label=label)
21942183
self.add_container(bar_container)
21952184

2196-
if label_ticks_flag:
2185+
if tick_labels is not None:
2186+
tick_labels = make_iterable(tick_labels)
2187+
if isinstance(tick_labels, six.string_types):
2188+
tick_labels = [tick_labels]
2189+
if len(tick_labels) == 1:
2190+
tick_labels *= nbars
2191+
if len(tick_labels) != nbars:
2192+
raise ValueError("incompatible sizes: argument 'tick_label' "
2193+
"must be length %d or string" % nbars)
2194+
21972195
tick_label_axis.set_ticks(tick_label_position)
2198-
tick_label_axis.set_ticklabels(tick_label)
2196+
tick_label_axis.set_ticklabels(tick_labels)
21992197

22002198
return bar_container
22012199

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,12 @@ def test_bar_tick_label_single():
10551055
ax.bar("a", "b" , tick_label='a', data=data)
10561056

10571057

1058+
@cleanup
1059+
def test_bar_ticklabel_fail():
1060+
fig, ax = plt.subplots()
1061+
ax.bar([], [])
1062+
1063+
10581064
@image_comparison(baseline_images=['bar_tick_label_multiple'],
10591065
extensions=['png'])
10601066
def test_bar_tick_label_multiple():
@@ -1082,6 +1088,7 @@ def test_hist_log():
10821088
ax = fig.add_subplot(111)
10831089
ax.hist(data, fill=False, log=True)
10841090

1091+
10851092
@image_comparison(baseline_images=['hist_bar_empty'], remove_text=True,
10861093
extensions=['png'])
10871094
def test_hist_bar_empty():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.