Thanks to visit codestin.com
Credit goes to github.com

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
28 changes: 26 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2285,12 +2285,21 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
height : float or array-like
The height(s) of the bars.

Note that if *bottom* has units (e.g. datetime), *height* should be in
units that are a difference from the value of *bottom* (e.g. timedelta).

width : float or array-like, default: 0.8
The width(s) of the bars.

Note that if *x* has units (e.g. datetime), then *width* should be in
units that are a difference (e.g. timedelta) around the *x* values.

bottom : float or array-like, default: 0
The y coordinate(s) of the bottom side(s) of the bars.

Note that if *bottom* has units, then the y-axis will get a Locator and
Formatter appropriate for the units (e.g. dates, or categorical).
Comment thread
QuLogic marked this conversation as resolved.

align : {'center', 'edge'}, default: 'center'
Alignment of the bars to the *x* coordinates:

Expand Down Expand Up @@ -2416,13 +2425,19 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
x = 0

if orientation == 'vertical':
# It is possible for y (bottom) to contain unit information.
# However, it is also possible for y=0 for the default and height
# to contain unit information. This will prioritize the units of y.
self._process_unit_info(
[("x", x), ("y", height)], kwargs, convert=False)
[("x", x), ("y", y), ("y", height)], kwargs, convert=False)
if log:
self.set_yscale('log', nonpositive='clip')
else: # horizontal
# It is possible for x (left) to contain unit information.
# However, it is also possible for x=0 for the default and width
# to contain unit information. This will prioritize the units of x.
self._process_unit_info(
[("x", width), ("y", y)], kwargs, convert=False)
[("x", x), ("x", width), ("y", y)], kwargs, convert=False)
if log:
self.set_xscale('log', nonpositive='clip')

Expand Down Expand Up @@ -2582,12 +2597,21 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
width : float or array-like
The width(s) of the bars.

Note that if *left* has units (e.g. datetime), *width* should be in
units that are a difference from the value of *left* (e.g. timedelta).

height : float or array-like, default: 0.8
The heights of the bars.

Note that if *y* has units (e.g. datetime), then *height* should be in
units that are a difference (e.g. timedelta) around the *y* values.

left : float or array-like, default: 0
The x coordinates of the left side(s) of the bars.

Note that if *left* has units, then the x-axis will get a Locator and
Formatter appropriate for the units (e.g. dates, or categorical).

align : {'center', 'edge'}, default: 'center'
Alignment of the base to the *y* coordinates*:

Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,22 @@ def test_bar_timedelta():
(10, 20))


def test_bar_datetime_start():
"""test that tickers are correct for datetimes"""
start = np.array([np.datetime64('2012-01-01'), np.datetime64('2012-02-01'),
np.datetime64('2012-01-15')])
stop = np.array([np.datetime64('2012-02-07'), np.datetime64('2012-02-13'),
np.datetime64('2012-02-12')])

fig, ax = plt.subplots()
ax.bar([0, 1, 3], height=stop-start, bottom=start)
assert isinstance(ax.yaxis.get_major_formatter(), mdates.AutoDateFormatter)

fig, ax = plt.subplots()
ax.barh([0, 1, 3], width=stop-start, left=start)
assert isinstance(ax.xaxis.get_major_formatter(), mdates.AutoDateFormatter)


def test_boxplot_dates_pandas(pd):
# smoke test for boxplot and dates in pandas
data = np.random.rand(5, 2)
Expand Down