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

Skip to content

Commit 6e3471d

Browse files
committed
Merge pull request #4196 from tacaswell/bar_doc
DOC/TST : document and test negative width to bar
2 parents f532615 + a57772a commit 6e3471d

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,52 +1819,63 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
18191819
height : sequence of scalars
18201820
the heights of the bars
18211821
1822-
width : scalar or array-like, optional, default: 0.8
1822+
width : scalar or array-like, optional
18231823
the width(s) of the bars
1824+
default: 0.8
18241825
1825-
bottom : scalar or array-like, optional, default: None
1826+
bottom : scalar or array-like, optional
18261827
the y coordinate(s) of the bars
1828+
default: None
18271829
18281830
color : scalar or array-like, optional
18291831
the colors of the bar faces
18301832
18311833
edgecolor : scalar or array-like, optional
18321834
the colors of the bar edges
18331835
1834-
linewidth : scalar or array-like, optional, default: None
1836+
linewidth : scalar or array-like, optional
18351837
width of bar edge(s). If None, use default
18361838
linewidth; If 0, don't draw edges.
1839+
default: None
18371840
1838-
xerr : scalar or array-like, optional, default: None
1841+
xerr : scalar or array-like, optional
18391842
if not None, will be used to generate errorbar(s) on the bar chart
1843+
default: None
18401844
1841-
yerr : scalar or array-like, optional, default: None
1845+
yerr : scalar or array-like, optional
18421846
if not None, will be used to generate errorbar(s) on the bar chart
1847+
default: None
18431848
1844-
ecolor : scalar or array-like, optional, default: None
1849+
ecolor : scalar or array-like, optional
18451850
specifies the color of errorbar(s)
1851+
default: None
18461852
1847-
capsize : integer, optional, default: 3
1853+
capsize : integer, optional
18481854
determines the length in points of the error bar caps
1855+
default: 3
18491856
1850-
error_kw :
1857+
error_kw : dict, optional
18511858
dictionary of kwargs to be passed to errorbar method. *ecolor* and
18521859
*capsize* may be specified here rather than as independent kwargs.
18531860
1854-
align : ['edge' | 'center'], optional, default: 'edge'
1855-
If `edge`, aligns bars by their left edges (for vertical bars) and
1856-
by their bottom edges (for horizontal bars). If `center`, interpret
1861+
align : {'edge', 'center'}, optional
1862+
If 'edge', aligns bars by their left edges (for vertical bars) and
1863+
by their bottom edges (for horizontal bars). If 'center', interpret
18571864
the `left` argument as the coordinates of the centers of the bars.
1865+
To align on the align bars on the right edge pass a negative
1866+
`width`.
18581867
1859-
orientation : 'vertical' | 'horizontal', optional, default: 'vertical'
1868+
orientation : {'vertical', 'horizontal'}, optional
18601869
The orientation of the bars.
18611870
1862-
log : boolean, optional, default: False
1863-
If true, sets the axis to be log scale
1871+
log : boolean, optional
1872+
If true, sets the axis to be log scale.
1873+
default: False
18641874
18651875
Returns
18661876
-------
1867-
`matplotlib.patches.Rectangle` instances.
1877+
bars : matplotlib.container.BarContainer
1878+
Container with all of the bars + errorbars
18681879
18691880
Notes
18701881
-----

lib/matplotlib/tests/test_axes.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_twinx_cla():
131131

132132
@image_comparison(baseline_images=["minorticks_on_rcParams_both"], extensions=['png'])
133133
def test_minorticks_on_rcParams_both():
134-
134+
135135
fig = plt.figure()
136136
matplotlib.rcParams['xtick.minor.visible'] = True
137137
matplotlib.rcParams['ytick.minor.visible'] = True
@@ -3569,24 +3569,28 @@ def test_pathological_hexbin():
35693569
fig.savefig(out)
35703570
assert_equal(len(w), 0)
35713571

3572+
35723573
@cleanup
35733574
def test_color_None():
35743575
# issue 3855
35753576
fig, ax = plt.subplots()
35763577
ax.plot([1,2], [1,2], color=None)
35773578

3579+
35783580
@cleanup
35793581
def test_color_alias():
35803582
# issues 4157 and 4162
35813583
fig, ax = plt.subplots()
35823584
line = ax.plot([0, 1], c='lime')[0]
35833585
assert_equal('lime', line.get_color())
35843586

3587+
35853588
@cleanup
35863589
def test_numerical_hist_label():
35873590
fig, ax = plt.subplots()
35883591
ax.hist([range(15)] * 5, label=range(5))
35893592

3593+
35903594
@cleanup
35913595
def test_move_offsetlabel():
35923596
data = np.random.random(10) * 1e-22
@@ -3595,6 +3599,18 @@ def test_move_offsetlabel():
35953599
ax.yaxis.tick_right()
35963600
assert_equal((1, 0.5), ax.yaxis.offsetText.get_position())
35973601

3602+
3603+
@cleanup
3604+
def test_bar_negative_width():
3605+
fig, ax = plt.subplots()
3606+
res = ax.bar(range(1, 5), range(1, 5), width=-1)
3607+
assert_equal(len(res), 4)
3608+
for indx, b in enumerate(res):
3609+
assert_equal(b._x, indx)
3610+
assert_equal(b._width, 1)
3611+
assert_equal(b._height, indx + 1)
3612+
3613+
35983614
if __name__ == '__main__':
35993615
import nose
36003616
import sys

0 commit comments

Comments
 (0)