Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Orthographic projection for mplot3d #8326
Conversation
dstansby
added the
mplot3d
label
Mar 18, 2017
dstansby
added this to the
2.1 (next point release)
milestone
Mar 18, 2017
dstansby
requested changes
Mar 19, 2017
Neat little new feature! Just a couple of implementation changes I've suggested.
| @@ -63,6 +63,7 @@ def __init__(self, fig, rect=None, *args, **kwargs): | ||
| *elev* Elevation viewing angle (default 30) | ||
| *zscale* [%(scale)s] | ||
| *sharez* Other axes to share z-limits with | ||
| + *persp* Perspective projection (default True) |
dstansby
Mar 19, 2017
Contributor
I think it would be better to have a proj argument instead, which (at the moment) could take either 'persp or ortho values, and default to persp.
txxia
Mar 19, 2017
Contributor
I agree. In that case, should I provide the setter set_proj? There is a get_proj which has different meaning.
dstansby
Mar 19, 2017
Contributor
Maybe use projection instead of proj to avoid breaking get_proj?
I think a better alternative would be to rename the current get_proj to get_proj_matrix - might be worth seeing what other devs think about that.
| + fig = plt.figure() | ||
| + ax = fig.gca(projection='3d') | ||
| + ax.set_persp(False) | ||
| + ax.set_xlabel('X') |
dstansby
Mar 19, 2017
Contributor
This test doesn't really need any text, so could the label lines be removed.
|
I am not too sure about this. The name |
| # eye point | ||
| E = np.array([1000, -1000, 2000]) | ||
| R = np.array([100, 100, 100]) | ||
| V = np.array([0, 0, 1]) | ||
| viewM = proj3d.view_transformation(E, R, V) | ||
| - perspM = proj3d.persp_transformation(100, -100) |
txxia
Mar 20, 2017
•
Contributor
I am not sure about this either. This seems to assume zfront and zback refer to the coordinates on the camera's Z axis (which is backwards), but judging from other places where it's called, they seem to be equivalent to near / far plane.
https://github.com/matplotlib/matplotlib/blob/master/lib/mpl_toolkits/mplot3d/axes3d.py#L1001
WeatherGod
Mar 29, 2017
Member
it is entirely possible this test was originally backwards. It came from some commented out code at the bottom of proj3d.py. Seemed like it might have been some debugging code for the original developer. We recently lifted it out of there and put it in as a unit test because it helped us solve a problem.
|
it is unfortunate name choice, but |
| - def get_proj(self): | ||
| + def set_proj(self, proj): | ||
| + """ | ||
| + Set the type of projection. |
WeatherGod
Mar 29, 2017
Member
Need to expand on this; detail what are the accepted inputs and what they mean.
txxia
Mar 29, 2017
Contributor
Do you think it will be okay if I rename the flag and this setter to proj_type? since I will keep get_proj, using set_proj would cause confusion.
WeatherGod
Mar 30, 2017
Member
Yes, I think your new setter/getter can be proj_type. I am a little leery of using the word "type" in a variable name when one is not referring to a type object, but I think it is ok here, especially if it is documented well.
| # eye point | ||
| E = np.array([1000, -1000, 2000]) | ||
| R = np.array([100, 100, 100]) | ||
| V = np.array([0, 0, 1]) | ||
| viewM = proj3d.view_transformation(E, R, V) | ||
| - perspM = proj3d.persp_transformation(100, -100) |
WeatherGod
Mar 29, 2017
Member
it is entirely possible this test was originally backwards. It came from some commented out code at the bottom of proj3d.py. Seemed like it might have been some debugging code for the original developer. We recently lifted it out of there and put it in as a unit test because it helped us solve a problem.
| + [0,2,0,0], | ||
| + [0,0,-2,0], | ||
| + [0,0,a,b] | ||
| + ]) |
WeatherGod
Mar 29, 2017
Member
Can you provide a reference for this formulation? I am not an expert in 3d transforms, but this doesn't match anything I am seeing on the wikipedia page for orthographic projection.
txxia
Mar 29, 2017
•
Contributor
Sorry, I should have justified it.
This matrix is almost equivalent to the one in the Wikipedia page. Based on persp_transformation, I made these assumptions:
zfrontis the value fornear,leftandbottomzbackforfar,right,top- the X and Y translations are omitted (I guess so the image will always be centered at the origin)
It's a simple derivation from the one from Wikipedia (v1), but since v2 and v1 are equivalent in homogeneous coordinates, I thought the second will look nicer.
WeatherGod
Mar 30, 2017
Member
ah, and if I transpose that, it then matches up. Got it. Well, just include some notes about it in comments for some future poor soul.
| @@ -961,9 +961,15 @@ def view_init(self, elev=None, azim=None): | ||
| else: | ||
| self.azim = azim | ||
| - def set_proj(self, proj): | ||
| + def set_proj_type(self, proj): |
|
This looks great. The only thing left to do is to add an entry to the what's new page: There should be some notes in doc/users/whats_new/ |
|
I am new to numpydoc. The file I created seems to compile, but I had trouble generating everything under |
|
we build the docs as part of our test suite. If it builds there, that should be sufficient. |
|
It would be nice to get more documentation for this feature, especially prose and graphics showing when this feature makes a significant improvement. However, that can be done in a separate PR. |
|
@dstansby , I take it that your concerns have been addressed? |
|
Sorry, this one dropped off my radar, looks like everything I mentioned has
been fixed so feel free to dismiss my review.
On 7 Apr 2017 4:11 pm, "Benjamin Root" <notifications@github.com> wrote:
@dstansby <https://github.com/dstansby> , I take it that your concerns have
been addressed?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8326 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF6RfH9KrjeDvP4Bw0nKEBxdhjyJWwnWks5rtlIwgaJpZM4MhS7y>
.
|
WeatherGod
merged commit 6f4cc13
into matplotlib:master
Apr 10, 2017
5 checks passed
|
Thanks to everybody! |
txxia commentedMar 18, 2017
•
edited
Fixes #537
ortho_transformation()in proj3dperspand a setterset_persp()Here is a simple demo: