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

Skip to content

Commit dd4051e

Browse files
committed
WIP : use container to draw errorbar
tests are still failing
1 parent 75bb0e8 commit dd4051e

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import six
55
from six.moves import reduce, xrange, zip, zip_longest
6-
6+
import itertools
77
import math
88
import warnings
99

@@ -35,7 +35,8 @@
3535
import matplotlib.transforms as mtransforms
3636
import matplotlib.tri as mtri
3737
import matplotlib.transforms as mtrans
38-
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
38+
from matplotlib.container import (BarContainer, ErrorbarContainer,
39+
StemContainer, Container)
3940
from matplotlib.axes._base import _AxesBase
4041
from matplotlib.axes._base import _process_plot_format
4142

@@ -2755,7 +2756,7 @@ def xywhere(xs, ys, mask):
27552756

27562757
if xerr is not None:
27572758
if (iterable(xerr) and len(xerr) == 2 and
2758-
iterable(xerr[0]) and iterable(xerr[1])):
2759+
iterable(xerr[0]) and iterable(xerr[1])):
27592760
# using list comps rather than arrays to preserve units
27602761
left = [thisx - thiserr for (thisx, thiserr)
27612762
in cbook.safezip(x, xerr[0])]
@@ -2886,14 +2887,18 @@ def xywhere(xs, ys, mask):
28862887
self.autoscale_view()
28872888
self._hold = holdstate
28882889

2889-
errorbar_container = ErrorbarContainer((l0, tuple(caplines),
2890-
tuple(barcols)),
2890+
# hack to put these artist in the right place in the
2891+
# draw tree
2892+
for ll in itertools.chain((l0, ), caplines, barcols):
2893+
ll.remove()
2894+
2895+
errorbar_container = ErrorbarContainer((l0,
2896+
Container(caplines),
2897+
Container(barcols)),
28912898
has_xerr=(xerr is not None),
28922899
has_yerr=(yerr is not None),
28932900
label=label)
2894-
self.containers.append(errorbar_container)
2895-
2896-
return errorbar_container # (l0, caplines, barcols)
2901+
return self.add_container(errorbar_container)
28972902

28982903
def boxplot(self, x, notch=False, sym=None, vert=True, whis=1.5,
28992904
positions=None, widths=None, patch_artist=False,

lib/matplotlib/axes/_base.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,13 +1605,19 @@ def add_container(self, container):
16051605
Add a :class:`~matplotlib.container.Container` instance
16061606
to the axes.
16071607
1608-
Returns the collection.
1608+
Returns the container.
16091609
"""
1610+
container.set_axes(self)
1611+
self._set_artist_props(container)
1612+
self.containers.append(container)
1613+
1614+
container.set_clip_path(self.patch)
1615+
container.set_remove_method(lambda h: self.containers.remove(h))
1616+
16101617
label = container.get_label()
16111618
if not label:
16121619
container.set_label('_container%d' % len(self.containers))
1613-
self.containers.append(container)
1614-
container.set_remove_method(lambda h: self.containers.remove(h))
1620+
16151621
return container
16161622

16171623
def relim(self, visible_only=False):
@@ -1998,6 +2004,7 @@ def draw(self, renderer=None, inframe=False):
19982004
artists.extend(self.lines)
19992005
artists.extend(self.texts)
20002006
artists.extend(self.artists)
2007+
artists.extend(self.containers)
20012008

20022009
# the frame draws the edges around the axes patch -- we
20032010
# decouple these so the patch can be in the background and the

lib/matplotlib/container.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class Container(tuple, Artist):
1010
"""
1111
Base class for containers.
1212
"""
13-
_no_broadcast = ['label', ]
13+
_no_broadcast = ['label', 'visible', 'zorder', 'animated',
14+
'agg_filter']
1415

1516
def __repr__(self):
1617
return "<Container object of %d artists>" % (len(self))
@@ -22,7 +23,7 @@ def __init__(self, kl, label=None, **kwargs):
2223
# set up the artist details
2324
Artist.__init__(self, **kwargs)
2425
# for some reason we special case label
25-
self.set_label(label=label)
26+
self.set_label(label)
2627

2728
def remove(self):
2829
# remove the children

0 commit comments

Comments
 (0)