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 422e78a

Browse filesBrowse files
authored
Merge pull request #7172 from tacaswell/api_bar_where
API: change default 'align' for bar and barh
2 parents 0370181 + f8ad443 commit 422e78a
Copy full SHA for 422e78a

File tree

Expand file treeCollapse file tree

3 files changed

+40
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+40
-3
lines changed

‎doc/users/dflt_style_changes.rst

Copy file name to clipboardExpand all lines: doc/users/dflt_style_changes.rst
+34-1Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ default. The default face color is now ``'C0'`` instead of ``'b'``.
500500
with rc_context(rc=rcparams):
501501
ax_top.pie(fracs, labels=labels)
502502
ax_top.set_aspect('equal')
503-
ax_mid.bar(range(len(fracs)), fracs, tick_label=labels, align='center')
503+
ax_mid.bar(range(len(fracs)), fracs, tick_label=labels)
504504
plt.setp(ax_mid.get_xticklabels(), rotation=-45)
505505
grid = np.mgrid[0.2:0.8:3j, 0.2:0.8:3j].reshape(2, -1).T
506506

@@ -529,6 +529,39 @@ or by setting::
529529

530530
in your :file:`matplotlibrc` file.
531531

532+
``bar`` and ``barh``
533+
====================
534+
535+
The default value of the ``align`` kwarg for both
536+
`~matplotlib.Axes.bar` and `~matplotlib.Axes.barh` is changed from
537+
``'edge'`` to ``'center'``.
538+
539+
540+
.. plot::
541+
542+
import matplotlib.pyplot as plt
543+
import numpy as np
544+
545+
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(5, 5))
546+
547+
def demo(bar_func, bar_kwargs):
548+
return bar_func([1, 2, 3], [1, 2, 3], tick_label=['a', 'b', 'c'],
549+
**bar_kwargs)
550+
551+
552+
ax1.set_title('2.0')
553+
554+
ax2.set_title("classic alignment")
555+
556+
demo(ax1.bar, {})
557+
demo(ax2.bar, {'align': 'edge'})
558+
demo(ax3.barh, {})
559+
demo(ax4.barh, {'align': 'edge'})
560+
561+
562+
To restore the previous behavior explicitly pass the keyword argument
563+
``align='edge'`` to the method call.
564+
532565

533566
Hatching
534567
========

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,11 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
19801980
error_kw.setdefault('ecolor', ecolor)
19811981
error_kw.setdefault('capsize', capsize)
19821982

1983-
align = kwargs.pop('align', 'edge')
1983+
if rcParams['_internal.classic_mode']:
1984+
align = kwargs.pop('align', 'edge')
1985+
else:
1986+
align = kwargs.pop('align', 'center')
1987+
19841988
orientation = kwargs.pop('orientation', 'vertical')
19851989
log = kwargs.pop('log', False)
19861990
label = kwargs.pop('label', '')

‎lib/matplotlib/tests/test_artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_artist.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_default_edges():
185185

186186
ax1.plot(np.arange(10), np.arange(10), 'x',
187187
np.arange(10) + 1, np.arange(10), 'o')
188-
ax2.bar(np.arange(10), np.arange(10))
188+
ax2.bar(np.arange(10), np.arange(10), align='edge')
189189
ax3.text(0, 0, "BOX", size=24, bbox=dict(boxstyle='sawtooth'))
190190
ax3.set_xlim((-1, 1))
191191
ax3.set_ylim((-1, 1))

0 commit comments

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