Skip to content

Fix typo in Axes3D.set_autoscalez_on. #7859

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 3 commits into from
Jan 28, 2017
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
105 changes: 55 additions & 50 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import warnings

import numpy as np
import matplotlib.axes as maxes
from matplotlib.axes import Axes, rcParams
from matplotlib import cbook
Expand All @@ -26,18 +27,19 @@
from matplotlib import docstring
import matplotlib.scale as mscale
from matplotlib.tri.triangulation import Triangulation
import numpy as np
from matplotlib import colors as mcolors
from matplotlib.colors import Normalize, LightSource

from . import art3d
from . import proj3d
from . import axis3d


def unit_bbox():
box = Bbox(np.array([[0, 0], [1, 1]]))
return box


class Axes3D(Axes):
"""
3D axes object.
Expand Down Expand Up @@ -302,7 +304,7 @@ def get_axis_position(self):
def update_datalim(self, xys, **kwargs):
pass

def get_autoscale_on(self) :
def get_autoscale_on(self):
"""
Get whether autoscaling is applied for all axes on plot commands

Expand All @@ -311,7 +313,7 @@ def get_autoscale_on(self) :
"""
return Axes.get_autoscale_on(self) and self.get_autoscalez_on()

def get_autoscalez_on(self) :
def get_autoscalez_on(self):
"""
Get whether autoscaling for the z-axis is applied on plot commands

Expand All @@ -320,7 +322,7 @@ def get_autoscalez_on(self) :
"""
return self._autoscaleZon

def set_autoscale_on(self, b) :
def set_autoscale_on(self, b):
"""
Set whether autoscaling is applied on plot commands

Expand All @@ -332,7 +334,7 @@ def set_autoscale_on(self, b) :
Axes.set_autoscale_on(self, b)
self.set_autoscalez_on(b)

def set_autoscalez_on(self, b) :
def set_autoscalez_on(self, b):
"""
Set whether autoscaling for the z-axis is applied on plot commands

Expand All @@ -341,9 +343,9 @@ def set_autoscalez_on(self, b) :
.. versionadded :: 1.1.0
This function was added, but not tested. Please report any bugs.
"""
self._autoscalez_on = b
self._autoscaleZon = b

def set_zmargin(self, m) :
def set_zmargin(self, m):
"""
Set padding of Z data limits prior to autoscaling.

Expand All @@ -360,7 +362,7 @@ def set_zmargin(self, m) :
self._zmargin = m
self.stale = True

def margins(self, *args, **kw) :
def margins(self, *args, **kw):
"""
Convenience method to set or retrieve autoscaling margins.

Expand Down Expand Up @@ -403,30 +405,36 @@ def margins(self, *args, **kw) :
mx = kw.pop('x', None)
my = kw.pop('y', None)
mz = kw.pop('z', None)
if len(args) == 1:
if not args:
pass
elif len(args) == 1:
mx = my = mz = args[0]
elif len(args) == 2:
# Maybe put out a warning because mz is not set?
warnings.warn(
"Passing exactly two positional arguments to Axes3D.margins "
"is deprecated. If needed, pass them as keyword arguments "
"instead", cbook.mplDeprecation)
mx, my = args
elif len(args) == 3:
mx, my, mz = args
else:
raise ValueError("more than three arguments were supplied")
raise ValueError(
"Axes3D.margins takes at most three positional arguments")
Copy link
Member

Choose a reason for hiding this comment

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

I raised a ValueError here originally because that what the 2d Axes.margins() does when given more than two arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May or may not be a gratuitious backwards compatible change but arguments mismatching the signature normally raise a TypeError. Should we change it in Axes.margins too? (hem hem)

Copy link
Member

Choose a reason for hiding this comment

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

along the same line of thinking, wouldn't the 2d version of this function suffer the same problem that you are trying to fix here with an empty args list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. Haven't checked the impl. but it must have been fixed at some point.

Copy link
Member

Choose a reason for hiding this comment

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

just took a look, it seems like the 2d version doesn't have this else-clause, so it silently allows more arguments than expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open a separate issue? :)

Copy link
Member

Choose a reason for hiding this comment

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

grrr, misread the code... it doesn't have an else clause... it has a "len(args) > 2" clause that then raises the ValueError, but also skips the case of no positional args. We are fine, then.

As for ValueError vs. TypeError, I really don't have a preference except that the 2d and 3d version be the same.

if mx is not None:
self.set_xmargin(mx)
if my is not None:
self.set_ymargin(my)
if mz is not None:
self.set_zmargin(mz)

scalex = (mx is not None)
scaley = (my is not None)
scalez = (mz is not None)
scalex = mx is not None
scaley = my is not None
scalez = mz is not None

self.autoscale_view(tight=tight, scalex=scalex, scaley=scaley,
scalez=scalez)

def autoscale(self, enable=True, axis='both', tight=None) :
def autoscale(self, enable=True, axis='both', tight=None):
"""
Convenience method for simple axis view autoscaling.
See :meth:`matplotlib.axes.Axes.autoscale` for full explanation.
Expand All @@ -442,18 +450,18 @@ def autoscale(self, enable=True, axis='both', tight=None) :
scaley = True
scalez = True
else:
scalex = False
scaley = False
scalez = False
if axis in ['x', 'both']:
self._autoscaleXon = bool(enable)
scalex = self._autoscaleXon
self._autoscaleXon = scalex = bool(enable)
else:
scalex = False
if axis in ['y', 'both']:
self._autoscaleYon = bool(enable)
scaley = self._autoscaleYon
self._autoscaleYon = scaley = bool(enable)
else:
scaley = False
if axis in ['z', 'both']:
self._autoscaleZon = bool(enable)
scalez = self._autoscaleZon
self._autoscaleZon = scalez = bool(enable)
else:
scalez = False
self.autoscale_view(tight=tight, scalex=scalex, scaley=scaley,
scalez=scalez)

Expand All @@ -477,7 +485,7 @@ def auto_scale_xyz(self, X, Y, Z=None, had_data=None):
self.autoscale_view()

def autoscale_view(self, tight=None, scalex=True, scaley=True,
scalez=True) :
scalez=True):
"""
Autoscale the view limits using the data limits.
See :meth:`matplotlib.axes.Axes.autoscale_view` for documentation.
Expand Down Expand Up @@ -631,7 +639,6 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
return left, right
set_xlim = set_xlim3d


def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
"""
Set 3D y limits.
Expand Down Expand Up @@ -765,7 +772,7 @@ def get_zlim3d(self):
return self.zz_viewLim.intervalx
get_zlim = get_zlim3d

def get_zscale(self) :
def get_zscale(self):
"""
Return the zaxis scale string %s

Expand All @@ -776,7 +783,7 @@ def get_zscale(self) :

# We need to slightly redefine these to pass scalez=False
# to their calls of autoscale_view.
def set_xscale(self, value, **kwargs) :
def set_xscale(self, value, **kwargs):
self.xaxis._set_scale(value, **kwargs)
self.autoscale_view(scaley=False, scalez=False)
self._update_transScale()
Expand All @@ -787,7 +794,7 @@ def set_xscale(self, value, **kwargs) :
This function was added, but not tested. Please report any bugs.
"""

def set_yscale(self, value, **kwargs) :
def set_yscale(self, value, **kwargs):
self.yaxis._set_scale(value, **kwargs)
self.autoscale_view(scalex=False, scalez=False)
self._update_transScale()
Expand All @@ -800,7 +807,7 @@ def set_yscale(self, value, **kwargs) :
"""

@docstring.dedent_interpd
def set_zscale(self, value, **kwargs) :
def set_zscale(self, value, **kwargs):
"""
Set the scaling of the z-axis: %(scale)s

Expand Down Expand Up @@ -846,7 +853,7 @@ def get_zticks(self, minor=False):
"""
return self.zaxis.get_ticklocs(minor=minor)

def get_zmajorticklabels(self) :
def get_zmajorticklabels(self):
"""
Get the ztick labels as a list of Text instances

Expand All @@ -855,7 +862,7 @@ def get_zmajorticklabels(self) :
return cbook.silent_list('Text zticklabel',
self.zaxis.get_majorticklabels())

def get_zminorticklabels(self) :
def get_zminorticklabels(self):
"""
Get the ztick labels as a list of Text instances

Expand All @@ -868,7 +875,7 @@ def get_zminorticklabels(self) :
return cbook.silent_list('Text zticklabel',
self.zaxis.get_minorticklabels())

def set_zticklabels(self, *args, **kwargs) :
def set_zticklabels(self, *args, **kwargs):
"""
Set z-axis tick labels.
See :meth:`matplotlib.axes.Axes.set_yticklabels` for more details.
Expand All @@ -880,7 +887,7 @@ def set_zticklabels(self, *args, **kwargs) :
"""
return self.zaxis.set_ticklabels(*args, **kwargs)

def get_zticklabels(self, minor=False) :
def get_zticklabels(self, minor=False):
"""
Get ztick labels as a list of Text instances.
See :meth:`matplotlib.axes.Axes.get_yticklabels` for more details.
Expand All @@ -893,7 +900,7 @@ def get_zticklabels(self, minor=False) :
return cbook.silent_list('Text zticklabel',
self.zaxis.get_ticklabels(minor=minor))

def zaxis_date(self, tz=None) :
def zaxis_date(self, tz=None):
"""
Sets up z-axis ticks and labels that treat the z data as dates.

Expand All @@ -910,7 +917,7 @@ def zaxis_date(self, tz=None) :
"""
self.zaxis.axis_date(tz)

def get_zticklines(self) :
def get_zticklines(self):
"""
Get ztick lines as a list of Line2D instances.
Note that this function is provided merely for completeness.
Expand Down Expand Up @@ -1033,15 +1040,15 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):
self._rotate_btn = np.atleast_1d(rotate_btn).tolist()
self._zoom_btn = np.atleast_1d(zoom_btn).tolist()

def can_zoom(self) :
def can_zoom(self):
"""
Return *True* if this axes supports the zoom box button functionality.

3D axes objects do not use the zoom box button.
"""
return False

def can_pan(self) :
def can_pan(self):
"""
Return *True* if this axes supports the pan/zoom button functionality.

Expand Down Expand Up @@ -1200,7 +1207,7 @@ def set_zlabel(self, zlabel, fontdict=None, labelpad=None, **kwargs):
if labelpad is not None : self.zaxis.labelpad = labelpad
return self.zaxis.set_label_text(zlabel, fontdict, **kwargs)

def get_zlabel(self) :
def get_zlabel(self):
"""
Get the z-label text string.

Expand Down Expand Up @@ -1271,12 +1278,12 @@ def grid(self, b=True, **kwargs):
This function was changed, but not tested. Please report any bugs.
'''
# TODO: Operate on each axes separately
if len(kwargs) :
if len(kwargs):
b = True
self._draw_grid = cbook._string_to_bool(b)
self.stale = True

def ticklabel_format(self, **kwargs) :
def ticklabel_format(self, **kwargs):
"""
Convenience method for manipulating the ScalarFormatter
used by default for linear axes in Axed3D objects.
Expand Down Expand Up @@ -1339,7 +1346,7 @@ def ticklabel_format(self, **kwargs) :
raise AttributeError(
"This method only works with the ScalarFormatter.")

def locator_params(self, axis='both', tight=None, **kwargs) :
def locator_params(self, axis='both', tight=None, **kwargs):
"""
Convenience method for controlling tick locators.

Expand All @@ -1364,7 +1371,7 @@ def locator_params(self, axis='both', tight=None, **kwargs) :
self.zaxis.get_major_locator().set_params(**kwargs)
self.autoscale_view(tight=tight, scalex=_x, scaley=_y, scalez=_z)

def tick_params(self, axis='both', **kwargs) :
def tick_params(self, axis='both', **kwargs):
"""
Convenience method for changing the appearance of ticks and
tick labels.
Expand Down Expand Up @@ -1465,8 +1472,6 @@ def set_zbound(self, lower=None, upper=None):
else :
self.set_zlim(upper, lower, auto=None)



def text(self, x, y, z, s, zdir=None, **kwargs):
'''
Add text to the plot. kwargs will be passed on to Axes.text,
Expand Down Expand Up @@ -1654,7 +1659,7 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
for rs in xrange(0, rows-1, rstride):
for cs in xrange(0, cols-1, cstride):
ps = []
for a in (X, Y, Z) :
for a in (X, Y, Z):
ztop = a[rs,cs:min(cols, cs+cstride+1)]
zleft = a[rs+1:min(rows, rs+rstride+1),
min(cols-1, cs+cstride)]
Expand Down Expand Up @@ -1838,14 +1843,14 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
if rstride:
rii = list(xrange(0, rows, rstride))
# Add the last index only if needed
if rows > 0 and rii[-1] != (rows - 1) :
if rows > 0 and rii[-1] != (rows - 1):
rii += [rows-1]
else:
rii = []
if cstride:
cii = list(xrange(0, cols, cstride))
# Add the last index only if needed
if cols > 0 and cii[-1] != (cols - 1) :
if cols > 0 and cii[-1] != (cols - 1):
cii += [cols-1]
else:
cii = []
Expand Down Expand Up @@ -2061,9 +2066,9 @@ def add_contour_set(self, cset, extend3d=False, stride=5, zdir='z', offset=None)
z = offset
art3d.line_collection_2d_to_3d(linec, z, zdir=zdir)

def add_contourf_set(self, cset, zdir='z', offset=None) :
def add_contourf_set(self, cset, zdir='z', offset=None):
zdir = '-' + zdir
for z, linec in zip(cset.levels, cset.collections) :
for z, linec in zip(cset.levels, cset.collections):
if offset is not None :
z = offset
art3d.poly_collection_2d_to_3d(linec, z, zdir=zdir)
Expand Down
12 changes: 12 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,15 @@ def test_lines_dists():

ax.set_xlim(-50, 150)
ax.set_ylim(0, 300)


@cleanup
def test_autoscale():
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.margins(x=0, y=.1, z=.2)
ax.plot([0, 1], [0, 1], [0, 1])
assert ax.get_w_lims() == (0, 1, -.1, 1.1, -.2, 1.2)
ax.autoscale(False)
ax.set_autoscalez_on(True)
ax.plot([0, 2], [0, 2], [0, 2])
assert ax.get_w_lims() == (0, 1, -.1, 1.1, -.4, 2.4)