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

Skip to content

Commit 1003cc1

Browse files
committed
WIP : use container to draw errorbar
tests are still failing
1 parent bc731ea commit 1003cc1

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
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
6-
6+
import itertools
77
import math
88
import warnings
99

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

@@ -2758,7 +2759,7 @@ def xywhere(xs, ys, mask):
27582759

27592760
if xerr is not None:
27602761
if (iterable(xerr) and len(xerr) == 2 and
2761-
iterable(xerr[0]) and iterable(xerr[1])):
2762+
iterable(xerr[0]) and iterable(xerr[1])):
27622763
# using list comps rather than arrays to preserve units
27632764
left = [thisx - thiserr for (thisx, thiserr)
27642765
in cbook.safezip(x, xerr[0])]
@@ -2889,14 +2890,18 @@ def xywhere(xs, ys, mask):
28892890
self.autoscale_view()
28902891
self._hold = holdstate
28912892

2892-
errorbar_container = ErrorbarContainer((l0, tuple(caplines),
2893-
tuple(barcols)),
2893+
# hack to put these artist in the right place in the
2894+
# draw tree
2895+
for ll in itertools.chain((l0, ), caplines, barcols):
2896+
ll.remove()
2897+
2898+
errorbar_container = ErrorbarContainer((l0,
2899+
Container(caplines),
2900+
Container(barcols)),
28942901
has_xerr=(xerr is not None),
28952902
has_yerr=(yerr is not None),
28962903
label=label)
2897-
self.containers.append(errorbar_container)
2898-
2899-
return errorbar_container # (l0, caplines, barcols)
2904+
return self.add_container(errorbar_container)
29002905

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

lib/matplotlib/axes/_base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,13 +1596,19 @@ def add_container(self, container):
15961596
Add a :class:`~matplotlib.container.Container` instance
15971597
to the axes.
15981598
1599-
Returns the collection.
1599+
Returns the container.
16001600
"""
1601+
container.set_axes(self)
1602+
self._set_artist_props(container)
1603+
self.containers.append(container)
1604+
1605+
container.set_clip_path(self.patch)
1606+
container.set_remove_method(lambda h: self.containers.remove(h))
1607+
16011608
label = container.get_label()
16021609
if not label:
16031610
container.set_label('_container%d' % len(self.containers))
1604-
self.containers.append(container)
1605-
container.set_remove_method(lambda h: self.containers.remove(h))
1611+
16061612
return container
16071613

16081614
def relim(self, visible_only=False):
@@ -1994,6 +2000,7 @@ def draw(self, renderer=None, inframe=False):
19942000
artists.extend(self.lines)
19952001
artists.extend(self.texts)
19962002
artists.extend(self.artists)
2003+
artists.extend(self.containers)
19972004

19982005
# the frame draws the edges around the axes patch -- we
19992006
# decouple these so the patch can be in the background and the
@@ -2038,7 +2045,7 @@ def draw(self, renderer=None, inframe=False):
20382045
# if the minimum zorder is negative, start rasterization
20392046
rasterization_zorder = self._rasterization_zorder
20402047
if (rasterization_zorder is not None and
2041-
len(dsu) > 0 and dsu[0][0] < rasterization_zorder):
2048+
len(dsu) > 0 and dsu[0][0] < rasterization_zorder):
20422049
renderer.start_rasterizing()
20432050
dsu_rasterized = [l for l in dsu if l[0] < rasterization_zorder]
20442051
dsu = [l for l in dsu if l[0] >= rasterization_zorder]

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)