Skip to content

Use autolim kwarg in add_collection to prevent duplication of effort. #3100

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 1 commit into from
Jun 2, 2014
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
31 changes: 16 additions & 15 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
for thisxmin, thisxmax, thisy in zip(xmin, xmax, y)]
coll = mcoll.LineCollection(verts, colors=colors,
linestyles=linestyles, label=label)
self.add_collection(coll)
self.add_collection(coll, autolim=False)
coll.update(kwargs)

if len(y) > 0:
Expand Down Expand Up @@ -1045,7 +1045,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
#print 'creating line collection'
coll = mcoll.LineCollection(verts, colors=colors,
linestyles=linestyles, label=label)
self.add_collection(coll)
self.add_collection(coll, autolim=False)
coll.update(kwargs)

if len(x) > 0:
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
linewidth=linewidth,
color=color,
linestyle=linestyle)
self.add_collection(coll)
self.add_collection(coll, autolim=False)
coll.update(kwargs)
colls.append(coll)

Expand Down Expand Up @@ -3937,7 +3937,7 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
self.autoscale_view(tight=True)

# add the collection last
self.add_collection(collection)
self.add_collection(collection, autolim=False)
if not marginals:
return collection

Expand Down Expand Up @@ -3983,7 +3983,7 @@ def coarse_bin(x, y, coarse):
hbar.set_norm(norm)
hbar.set_alpha(alpha)
hbar.update(kwargs)
self.add_collection(hbar)
self.add_collection(hbar, autolim=False)

coarse = np.linspace(ymin, ymax, gridsize)
ycoarse = coarse_bin(yorig, C, coarse)
Expand Down Expand Up @@ -4011,7 +4011,7 @@ def coarse_bin(x, y, coarse):
vbar.set_norm(norm)
vbar.set_alpha(alpha)
vbar.update(kwargs)
self.add_collection(vbar)
self.add_collection(vbar, autolim=False)

collection.hbar = hbar
collection.vbar = vbar
Expand Down Expand Up @@ -4073,7 +4073,7 @@ def quiver(self, *args, **kw):
self.cla()
q = mquiver.Quiver(self, *args, **kw)

self.add_collection(q, True)
self.add_collection(q, autolim=True)
self.autoscale_view()
return q
quiver.__doc__ = mquiver.Quiver.quiver_doc
Expand Down Expand Up @@ -4113,7 +4113,7 @@ def barbs(self, *args, **kw):
if not self._hold:
self.cla()
b = mquiver.Barbs(self, *args, **kw)
self.add_collection(b)
self.add_collection(b, autolim=True)
self.autoscale_view()
return b

Expand Down Expand Up @@ -4301,9 +4301,10 @@ def get_interp_point(ind):
XY2 = np.array([x[where], y2[where]]).T
self.dataLim.update_from_data_xy(XY1, self.ignore_existing_data_limits,
updatex=True, updatey=True)
self.ignore_existing_data_limits = False
Copy link
Member

Choose a reason for hiding this comment

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

Why did this get added?

Copy link
Member Author

Choose a reason for hiding this comment

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

This flag is initialized to True by cla(); subsequently, anything that updates the dataLim needs to set it to False so that the updating is cumulative rather than starting again from scratch.

self.dataLim.update_from_data_xy(XY2, self.ignore_existing_data_limits,
updatex=False, updatey=True)
self.add_collection(collection)
self.add_collection(collection, autolim=False)
self.autoscale_view()
return collection

Expand Down Expand Up @@ -4408,10 +4409,10 @@ def fill_betweenx(self, y, x1, x2=0, where=None, **kwargs):
X2Y = np.array([x2[where], y[where]]).T
self.dataLim.update_from_data_xy(X1Y, self.ignore_existing_data_limits,
updatex=True, updatey=True)

self.ignore_existing_data_limits = False
self.dataLim.update_from_data_xy(X2Y, self.ignore_existing_data_limits,
updatex=False, updatey=True)
self.add_collection(collection)
updatex=True, updatey=False)
self.add_collection(collection, autolim=False)
self.autoscale_view()
return collection

Expand Down Expand Up @@ -4886,7 +4887,7 @@ def pcolor(self, *args, **kwargs):
corners = (minx, miny), (maxx, maxy)
self.update_datalim(corners)
self.autoscale_view()
self.add_collection(collection)
self.add_collection(collection, autolim=False)
return collection

@docstring.dedent_interpd
Expand Down Expand Up @@ -5032,7 +5033,7 @@ def pcolormesh(self, *args, **kwargs):
corners = (minx, miny), (maxx, maxy)
self.update_datalim(corners)
self.autoscale_view()
self.add_collection(collection)
self.add_collection(collection, autolim=False)
Copy link
Member

Choose a reason for hiding this comment

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

I think the better solution (but not the quicker solution, so I'm happy this PR was merged) would be to implement an appropriate data limit updater on the QuadMeshCollection - I'm not sure I'll get around to doing this anytime soon, so just wanted to post it here as a reminder.

return collection

@docstring.dedent_interpd
Expand Down Expand Up @@ -5184,7 +5185,7 @@ def pcolorfast(self, *args, **kwargs):
collection.set_array(C)
collection.set_cmap(cmap)
collection.set_norm(norm)
self.add_collection(collection)
self.add_collection(collection, autolim=False)
xl, xr, yb, yt = X.min(), X.max(), Y.min(), Y.max()
ret = collection

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def __init__(self, ax, *args, **kwargs):
alpha=self.alpha,
transform=self.get_transform(),
zorder=zorder)
self.ax.add_collection(col)
self.ax.add_collection(col, autolim=False)
self.collections.append(col)
else:
tlinewidths = self._process_linewidths()
Expand All @@ -961,7 +961,7 @@ def __init__(self, ax, *args, **kwargs):
transform=self.get_transform(),
zorder=zorder)
col.set_label('_nolegend_')
self.ax.add_collection(col, False)
self.ax.add_collection(col, autolim=False)
self.collections.append(col)
self.changed() # set the colors

Expand Down