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

Skip to content

DOC/TST : document and test negative width to bar #4196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2015
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
41 changes: 26 additions & 15 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,52 +1819,63 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
height : sequence of scalars
the heights of the bars

width : scalar or array-like, optional, default: 0.8
width : scalar or array-like, optional
the width(s) of the bars
default: 0.8

bottom : scalar or array-like, optional, default: None
bottom : scalar or array-like, optional
the y coordinate(s) of the bars
default: None

color : scalar or array-like, optional
the colors of the bar faces

edgecolor : scalar or array-like, optional
the colors of the bar edges

linewidth : scalar or array-like, optional, default: None
linewidth : scalar or array-like, optional
width of bar edge(s). If None, use default
linewidth; If 0, don't draw edges.
default: None

xerr : scalar or array-like, optional, default: None
xerr : scalar or array-like, optional
if not None, will be used to generate errorbar(s) on the bar chart
default: None

yerr : scalar or array-like, optional, default: None
yerr : scalar or array-like, optional
if not None, will be used to generate errorbar(s) on the bar chart
default: None

ecolor : scalar or array-like, optional, default: None
ecolor : scalar or array-like, optional
specifies the color of errorbar(s)
default: None

capsize : integer, optional, default: 3
capsize : integer, optional
determines the length in points of the error bar caps
default: 3

error_kw :
error_kw : dict, optional
dictionary of kwargs to be passed to errorbar method. *ecolor* and
*capsize* may be specified here rather than as independent kwargs.

align : ['edge' | 'center'], optional, default: 'edge'
If `edge`, aligns bars by their left edges (for vertical bars) and
by their bottom edges (for horizontal bars). If `center`, interpret
align : {'edge', 'center'}, optional
If 'edge', aligns bars by their left edges (for vertical bars) and
Copy link
Member

Choose a reason for hiding this comment

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

Is it on purpose that default has dropped out here?

by their bottom edges (for horizontal bars). If 'center', interpret
the `left` argument as the coordinates of the centers of the bars.
To align on the align bars on the right edge pass a negative
`width`.

orientation : 'vertical' | 'horizontal', optional, default: 'vertical'
orientation : {'vertical', 'horizontal'}, optional
The orientation of the bars.
Copy link
Member

Choose a reason for hiding this comment

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

Same

Copy link
Member

Choose a reason for hiding this comment

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

A clear indication of the default is critical; I wonder whether this can be handled by scrupulously adhering to a convention in which the first alternative is the default.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is the convention (first is default) specified in the numpydoc style
guide

On Sun, Apr 5, 2015, 14:50 Eric Firing [email protected] wrote:

In lib/matplotlib/axes/_axes.py
#4196 (comment):

  •    orientation : 'vertical' | 'horizontal', optional, default: 'vertical'
    
  •    orientation : {'vertical',  'horizontal'}, optional
         The orientation of the bars.
    

A clear indication of the default is critical; I wonder whether this can
be handled by scrupulously adhering to a convention in which the first
alternative is the default.


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/4196/files#r27779543.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarifying I'm 👍 on merging this now then but unfortunately needs a rebase


log : boolean, optional, default: False
If true, sets the axis to be log scale
log : boolean, optional
If true, sets the axis to be log scale.
default: False

Returns
-------
`matplotlib.patches.Rectangle` instances.
bars : matplotlib.container.BarContainer
Container with all of the bars + errorbars

Notes
-----
Expand Down
18 changes: 17 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_twinx_cla():

@image_comparison(baseline_images=["minorticks_on_rcParams_both"], extensions=['png'])
def test_minorticks_on_rcParams_both():

fig = plt.figure()
matplotlib.rcParams['xtick.minor.visible'] = True
matplotlib.rcParams['ytick.minor.visible'] = True
Expand Down Expand Up @@ -3569,24 +3569,28 @@ def test_pathological_hexbin():
fig.savefig(out)
assert_equal(len(w), 0)


@cleanup
def test_color_None():
# issue 3855
fig, ax = plt.subplots()
ax.plot([1,2], [1,2], color=None)


@cleanup
def test_color_alias():
# issues 4157 and 4162
fig, ax = plt.subplots()
line = ax.plot([0, 1], c='lime')[0]
assert_equal('lime', line.get_color())


@cleanup
def test_numerical_hist_label():
fig, ax = plt.subplots()
ax.hist([range(15)] * 5, label=range(5))


@cleanup
def test_move_offsetlabel():
data = np.random.random(10) * 1e-22
Expand All @@ -3595,6 +3599,18 @@ def test_move_offsetlabel():
ax.yaxis.tick_right()
assert_equal((1, 0.5), ax.yaxis.offsetText.get_position())


@cleanup
def test_bar_negative_width():
fig, ax = plt.subplots()
res = ax.bar(range(1, 5), range(1, 5), width=-1)
assert_equal(len(res), 4)
for indx, b in enumerate(res):
assert_equal(b._x, indx)
assert_equal(b._width, 1)
assert_equal(b._height, indx + 1)


if __name__ == '__main__':
import nose
import sys
Expand Down