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

Skip to content

Style fixes for mplot3d. #12069

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
Sep 14, 2018
Merged

Style fixes for mplot3d. #12069

merged 1 commit into from
Sep 14, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 8, 2018

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

angle = 0.
else:
angle = math.degrees(math.atan2(dy, dx))
angle = math.degrees(math.atan2(dy, dx))
Copy link
Contributor Author

@anntzer anntzer Sep 8, 2018

Choose a reason for hiding this comment

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

math.atan2(0, 0) (or likewise with floats) returns 0 or pi depending on the signedness of the zeros in Py2 and Py3 and that's also mandated by the C standard. norm_text_angle later takes it modulo 180 so we're fine.

# FIXME: Some results still don't look quite right.
# In particular, examine contourf3d_demo2.py
# with az = -54 and elev = -45.
return np.min(tzs)
else :
else:
Copy link
Member

@timhoffm timhoffm Sep 9, 2018

Choose a reason for hiding this comment

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

else:
    return np.min(tzs) if tzs.size else np.nan

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see where you're coming from but mixing in a ternary in a if... elif chain looks meh to me.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I don't think that the three blocks are logically equal. To me, the current form

if self._sort_zpos is not None:
    [use _sort_zpos]
elif tzs.size > 0:
    [use min(tzs)]
else:
    [use fallback]

is logically more like

if self._sort_zpos is not None:
    [use _sort_zpos]
else:
    if tzs.size > 0:
        [use min(tzs)]
    else:
        [use fallback]

Usually tzs are expected to be there and nan is only a fallback if they are not. Thus it would be preferable to

if self._sort_zpos is not None:
    [use _sort_zpos]
else:
    [use min(tzs) with fallback]

However, I agree that depends on the point of view you take. And I won't argue further if you still prefer to leave it as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know (hence the "I see where you're coming from" above), but it still looks not so nice to me. (Really, best would be min(tzs, default=np.nan) but np.min doesn't have that and builtins.min is likely slower.)

else :
zsortval = 0 # FIXME: Fairly arbitrary. Is there a better value?
zsortval = (
np.min(zvals) if zvals.size else 0) # FIXME: arbitrary default
Copy link
Member

Choose a reason for hiding this comment

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

Slightly better:

default_z = 0  # FIXME: arbitrary default
zsortval = np.min(zvals) if zvals.size else default_z

Copy link
Contributor Author

Choose a reason for hiding this comment

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

went for some middle ground

@@ -2485,7 +2485,8 @@ def quiver(self, *args,
length=1, arrow_length_ratio=.3, pivot='tail', normalize=False,
**kwargs):
"""
ax.quiver(X, Y, Z, U, V, W, /, length=1, arrow_length_ratio=.3, pivot='tail', normalize=False, **kwargs)
ax.quiver(X, Y, Z, U, V, W, /, length=1, arrow_length_ratio=.3, \
pivot='tail', normalize=False, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Can this be indented to align with the bracket in the line above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really, that'll look awkward in the actual docstring (the problem is the same as always re: line continuations in rst).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think treating the first line of the docstring as a replacement __signature__ is a sphinx thing, not an rst thing - it's possible it gets handled before the RST parser kicks in.

@tacaswell tacaswell added this to the v3.1 milestone Sep 12, 2018
@NelleV
Copy link
Member

NelleV commented Sep 14, 2018

Thanks @anntzer !

@NelleV NelleV merged commit 6a896b0 into matplotlib:master Sep 14, 2018
@anntzer anntzer deleted the 3dstyle branch September 14, 2018 16:53
@anntzer anntzer mentioned this pull request Sep 17, 2018
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants