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

Skip to content

3D margins consistency for mplot3d (isometric projection) #13358

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
Feb 16, 2021

Conversation

t-bltg
Copy link

@t-bltg t-bltg commented Feb 4, 2019

mwe

from mpl_toolkits.mplot3d import proj3d
import pylab as plt
import numpy as np
import itertools
import math

# the following code snippet should plot a 3D cube, with apparent equal edge lengths
kw_3d = dict(proj_type='ortho', projection='3d', aspect='equal')

_, ax = plt.subplots(subplot_kw=kw_3d)
ax.grid(1)

# draw cube (stackoverflow.com/a/11156353)
r = (-1, 1)
for s, e in itertools.combinations(np.array(list(itertools.product(r, r, r))), 2):
    if abs(s - e).sum() == r[1] - r[0]:
        ax.plot3D(*zip(s, e), c='C0')

# isometric projection (en.wikipedia.org/wiki/Isometric_projection)
ax.view_init(elev=math.degrees(math.atan(1 / math.sqrt(2))), azim=-45)

# annotation
px, py, pz = 1, -1, 1
ax.plot([px], [py], [pz], 'o', ms=10, mfc='none', c='C1')

x, y, _ = proj3d.proj_transform(px, py, pz, ax.get_proj())
xt, yt, _ = proj3d.proj_transform(px, py + .6, pz + .6, ax.get_proj())

ax.annotate('Isometric', (x, y), xytext=(xt, yt), arrowprops=dict(arrowstyle='->'))

plt.savefig('cube.png', dpi=300)

without proposed patch
cube_nok

with current PR
cube_ok

@t-bltg t-bltg changed the title 3D margins consistency for Axes3D (isometric projection) 3D margins consistency for mplot3d (isometric projection) Feb 4, 2019
@t-bltg t-bltg closed this Feb 5, 2019
@t-bltg t-bltg reopened this Feb 5, 2019
@QuLogic
Copy link
Member

QuLogic commented Sep 25, 2020

This seems to have been forgotten for a while, but I don't see why it shouldn't go in. It will need a rebase though.

I also wonder what effect there would be if the margin were always added (for defaults), even for perspective projections.

@t-bltg t-bltg force-pushed the isometric branch 2 times, most recently from 4f87fc2 to f3486fa Compare February 13, 2021 00:05
@t-bltg
Copy link
Author

t-bltg commented Feb 13, 2021

This seems to have been forgotten for a while, but I don't see why it shouldn't go in. It will need a rebase though.

Hi @QuLogic and @timhoffm, I squashed all the previous commits and updated this branch against latest master.
All tests are passing so I think that this (old) PR is ready to merge, if you don't see any objection.

@t-bltg t-bltg requested a review from timhoffm February 13, 2021 00:55
@QuLogic QuLogic added this to the v3.4.0 milestone Feb 16, 2021
@QuLogic QuLogic merged commit dbed8a0 into matplotlib:master Feb 16, 2021
@t-bltg t-bltg deleted the isometric branch February 16, 2021 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants