diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 1f93652e09dd..1980e5e9e20c 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -522,7 +522,7 @@ def set_figure(self, fig): self.bbox = mtransforms.TransformedBbox(self._position, fig.transFigure) # these will be updated later as data is added - self.dataLim = mtransforms.Bbox.unit() + self.dataLim = mtransforms.Bbox.null() self.viewLim = mtransforms.Bbox.unit() self.transScale = mtransforms.TransformWrapper( mtransforms.IdentityTransform()) @@ -1625,13 +1625,16 @@ def relim(self): # Collections are deliberately not supported (yet); see # the TODO note in artists.py. self.dataLim.ignore(True) + self.dataLim.set_points(mtransforms.Bbox.null().get_points()) self.ignore_existing_data_limits = True + for line in self.lines: self._update_line_limits(line) for p in self.patches: self._update_patch_limits(p) + def update_datalim(self, xys, updatex=True, updatey=True): """ Update the data lim bbox with seq of xy tups or equiv. 2-D array @@ -8290,14 +8293,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: w = [None]*nx - # Save autoscale state for later restoration; turn autoscaling - # off so we can do it all a single time at the end, instead - # of having it done by bar or fill and then having to be redone. - _saved_autoscalex = self.get_autoscalex_on() - _saved_autoscaley = self.get_autoscaley_on() - self.set_autoscalex_on(False) - self.set_autoscaley_on(False) - # Save the datalimits for the same reason: _saved_bounds = self.dataLim.bounds @@ -8355,6 +8350,14 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, patches = [] if histtype.startswith('bar'): + # Save autoscale state for later restoration; turn autoscaling + # off so we can do it all a single time at the end, instead + # of having it done by bar or fill and then having to be redone. + _saved_autoscalex = self.get_autoscalex_on() + _saved_autoscaley = self.get_autoscaley_on() + self.set_autoscalex_on(False) + self.set_autoscaley_on(False) + totwidth = np.diff(bins) if rwidth is not None: @@ -8404,6 +8407,10 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, bottom[:] = m boffset += dw + self.set_autoscalex_on(_saved_autoscalex) + self.set_autoscaley_on(_saved_autoscaley) + self.autoscale_view() + elif histtype.startswith('step'): # these define the perimeter of the polygon x = np.zeros(4 * len(bins) - 3, np.float) @@ -8467,11 +8474,11 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, for x, y, c in reversed(zip(xvals, yvals, color)): if fill: patches.append(self.fill(x, y, - closed=False, + closed=True, facecolor=c)) else: patches.append(self.fill(x, y, - closed=False, edgecolor=c, + closed=True, edgecolor=c, fill=False)) # we return patches, so put it back in the expected order @@ -8529,10 +8536,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, self.update_datalim( [(0, bins[0]), (0, bins[-1])], updatex=False) - self.set_autoscalex_on(_saved_autoscalex) - self.set_autoscaley_on(_saved_autoscaley) - self.autoscale_view() - if nx == 1: return n[0], bins, cbook.silent_list('Patch', patches[0]) else: diff --git a/lib/matplotlib/tests/baseline_images/test_scale/log_scales.pdf b/lib/matplotlib/tests/baseline_images/test_scale/log_scales.pdf index 24b284d9f7a7..182416404c08 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_scale/log_scales.pdf and b/lib/matplotlib/tests/baseline_images/test_scale/log_scales.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_scale/log_scales.png b/lib/matplotlib/tests/baseline_images/test_scale/log_scales.png index 939961f0dcbc..52bb6bd9a2b5 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_scale/log_scales.png and b/lib/matplotlib/tests/baseline_images/test_scale/log_scales.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_scale/log_scales.svg b/lib/matplotlib/tests/baseline_images/test_scale/log_scales.svg index 9c6f9cfecafb..db0974b7495f 100644 --- a/lib/matplotlib/tests/baseline_images/test_scale/log_scales.svg +++ b/lib/matplotlib/tests/baseline_images/test_scale/log_scales.svg @@ -35,8 +35,8 @@ L393.006 43.2" style="fill:none;stroke:#0000ff;"/> +M315.491 256.775 +L518.4 256.775" style="fill:none;stroke:#0000ff;"/> @@ -134,550 +134,118 @@ L-4 0" id="m0d5b0a6425" style="stroke:#000000;stroke-linecap:butt;stroke-width:0 - + - + + + + - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a812e3b14418..bf0d509725e4 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1610,6 +1610,17 @@ def make_patch_spines_invisible(ax): host.tick_params(axis='x', **tkw) +@cleanup +def test_vline_limit(): + fig = plt.figure() + ax = fig.gca() + ax.axvline(0.5) + ax.plot([-0.1, 0, 0.2, 0.1]) + (ymin, ymax) = ax.get_ylim() + assert ymin == -0.1 + assert ymax == 0.25 + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_transforms.py b/lib/matplotlib/tests/test_transforms.py index 54586d608c1a..95d28a3cbef3 100644 --- a/lib/matplotlib/tests/test_transforms.py +++ b/lib/matplotlib/tests/test_transforms.py @@ -359,7 +359,7 @@ def test_line_extent_axes_coords(self): # a simple line in axes coordinates ax = plt.axes() ax.plot([0.1, 1.2, 0.8], [0.9, 0.5, 0.8], transform=ax.transAxes) - np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[0, 0], [1, 1]])) + np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[np.inf, np.inf], [-np.inf, -np.inf]])) def test_line_extent_data_coords(self): # a simple line in data coordinates @@ -372,7 +372,7 @@ def test_line_extent_compound_coords1(self): ax = plt.axes() trans = mtrans.blended_transform_factory(ax.transAxes, ax.transData) ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans) - np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0., -5.], [ 1., 35.]])) + np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ np.inf, -5.], [ -np.inf, 35.]])) plt.close() def test_line_extent_predata_transform_coords(self): @@ -388,7 +388,7 @@ def test_line_extent_compound_coords2(self): ax = plt.axes() trans = mtrans.blended_transform_factory(ax.transAxes, mtrans.Affine2D().scale(10) + ax.transData) ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans) - np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0., -50.], [ 1., 350.]])) + np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ np.inf, -50.], [ -np.inf, 350.]])) plt.close() def test_line_extents_affine(self): diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index e2ff4ba3222d..68491c3c3610 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -774,7 +774,7 @@ def __init__(self, points, **kwargs): BboxBase.__init__(self, **kwargs) points = np.asarray(points, np.float_) if points.shape != (2, 2): - raise ValueError('Bbox points must be of the form ' + raise ValueError('Bbox points must be of the form ' '"[[x0, y0], [x1, y1]]".') self._points = points self._minpos = np.array([0.0000001, 0.0000001]) @@ -794,15 +794,21 @@ def invalidate(self): self._check(self._points) TransformNode.invalidate(self) - _unit_values = np.array([[0.0, 0.0], [1.0, 1.0]], np.float_) - @staticmethod def unit(): """ (staticmethod) Create a new unit :class:`Bbox` from (0, 0) to (1, 1). """ - return Bbox(Bbox._unit_values.copy()) + return Bbox(np.array([[0.0, 0.0], [1.0, 1.0]], np.float)) + + @staticmethod + def null(): + """ + (staticmethod) Create a new null :class:`Bbox` from (inf, inf) to + (-inf, -inf). + """ + return Bbox(np.array([[np.inf, np.inf], [-np.inf, -np.inf]], np.float)) @staticmethod def from_bounds(x0, y0, width, height):