X Tutup
Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion doc/users/dflt_style_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ default. The default face color is now ``'C0'`` instead of ``'b'``.
with rc_context(rc=rcparams):
ax_top.pie(fracs, labels=labels)
ax_top.set_aspect('equal')
ax_mid.bar(range(len(fracs)), fracs, tick_label=labels, align='center')
ax_mid.bar(range(len(fracs)), fracs, tick_label=labels)
plt.setp(ax_mid.get_xticklabels(), rotation=-45)
grid = np.mgrid[0.2:0.8:3j, 0.2:0.8:3j].reshape(2, -1).T

Expand Down Expand Up @@ -529,6 +529,39 @@ or by setting::

in your :file:`matplotlibrc` file.

``bar`` and ``barh``
====================

The default value of the ``align`` kwarg for both
`~matplotlib.Axes.bar` and `~matplotlib.Axes.barh` is changed from
``'edge'`` to ``'center'``.


.. plot::

import matplotlib.pyplot as plt
import numpy as np

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(5, 5))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why put this before the function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. A bunch of the example on this page page this ordering.


def demo(bar_func, bar_kwargs):
return bar_func([1, 2, 3], [1, 2, 3], tick_label=['a', 'b', 'c'],
**bar_kwargs)


ax1.set_title('2.0')

ax2.set_title("classic alignment")

demo(ax1.bar, {})
demo(ax2.bar, {'align': 'edge'})
demo(ax3.barh, {})
demo(ax4.barh, {'align': 'edge'})


To restore the previous behavior explicitly pass the keyword argument
``align='edge'`` to the method call.


Hatching
========
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,11 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
error_kw.setdefault('ecolor', ecolor)
error_kw.setdefault('capsize', capsize)

align = kwargs.pop('align', 'edge')
if rcParams['_internal.classic_mode']:
align = kwargs.pop('align', 'edge')
else:
align = kwargs.pop('align', 'center')

orientation = kwargs.pop('orientation', 'vertical')
log = kwargs.pop('log', False)
label = kwargs.pop('label', '')
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_default_edges():

ax1.plot(np.arange(10), np.arange(10), 'x',
np.arange(10) + 1, np.arange(10), 'o')
ax2.bar(np.arange(10), np.arange(10))
ax2.bar(np.arange(10), np.arange(10), align='edge')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not quite "default" edges now... Not strictly necessary to update, though.

ax3.text(0, 0, "BOX", size=24, bbox=dict(boxstyle='sawtooth'))
ax3.set_xlim((-1, 1))
ax3.set_ylim((-1, 1))
Expand Down
X Tutup