8000 API: change default 'align' for bar and barh · matplotlib/matplotlib@c148057 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit c148057

Browse files
committed
API: change default 'align' for bar and barh
Change from 'edge' to 'center'
1 parent 0370181 commit c148057

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

doc/users/dflt_style_changes.rst

Lines changed: 33 additions & 0 deletions
< 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -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 8000 `` 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 default explicitly pass a the kwarg
563+
``align='edge'`` to the method call.
564+
532565

533566
Hatching
534567
========

lib/matplotlib/axes/_axes.py

Lines 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

Lines 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