Skip to content

Commit

Permalink
Merge pull request #2082 from mdboom/data_limits
Browse files Browse the repository at this point in the history
Data limits (on 1.3.x)
  • Loading branch information
mdboom committed May 29, 2013
2 parents 212a8f9 + 412f1b3 commit d7968d0
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 484 deletions.
33 changes: 18 additions & 15 deletions lib/matplotlib/axes.py
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_scale/log_scales.pdf
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_scale/log_scales.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d7968d0

Please sign in to comment.