-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
2d slices in 3d plot #3919
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
Comments
Slices, yes (sort of, with contourf(), not imshow()), but they can not They haven't ported mayavi yet?! Another project to take a look at for true I hope that helps! On Sat, Dec 13, 2014 at 2:18 PM, Thomas Hisch [email protected]
|
Do you have an example, which shows how to plot data on a plane (x,y,z + color) in a Axes3d ? mayavi depends on vtk, therefore it is also py2 only. |
You would use the "offset" and the "zdir" arguments to the contourf() call Keep in mind, those examples are surface data rather than a 3D image data, I repeat the importance of needing to split up the image slices. You would On Sat, Dec 13, 2014 at 4:46 PM, Thomas Hisch [email protected]
|
I see. Does this also work if I rotate the Axes interactively? |
How do I set the zorder of the planes in the code below?
edit: |
It should work with rotation just fine. You don't mess around with zorder. mplot3d computes it dynamically to help On Sat, Dec 13, 2014 at 5:43 PM, Thomas Hisch [email protected]
|
Seems like we've resolved this @WeatherGod? |
The last time I tested it, it did not work satisfactorily AFAIR. |
Have you tried glumpy, which I originally suggested? It is possible to
create a function that could possibly do all of this for you, but it will
still suffer from possible rendering artifacts at certain viewing angles,
and it would still be a hack because it would use contourf() instead of
imshow(). I would imagine glumpy would be much better suited for this need.
β¦On Thu, Jan 5, 2017 at 11:13 PM, Thomas Hisch ***@***.***> wrote:
The last time I tested it, it did not work satisfactorily AFAIR.
β
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3919 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-GVP1tnNsoMJXLDnY_qIJSjZM3Z8ks5rPb9dgaJpZM4DIDoZ>
.
|
As explained in this stackoverflow answer, matplotlib won't be able to make the 3 slices plots on the same figure "until OpenGL support is added to all of the backends". Indeed, occlusions of the different slices will not be rendered correctly, and you will get this kind of result (I plot the 3d function (x,y,z) -> x^2 + y^2 + z^2 over the domain [-1,1]^3) : However, you can plot each slice on a separate figure : or plot slices that do not occlude each other from the point of view you are looking from. code :
|
You might actually overcome this issue using matplotlib Poly3DCollection, see example, but as you can read in the doc :"this class (Poly3DCollection) does a bit of magic with the _facecolors and _edgecolors properties."... Let me know if you manage to do it :-). |
There is an example of solution using plotly. |
Also see https://stackoverflow.com/questions/14824893/how-to-draw-intersecting-planes/14825951#14825951 . Manually chopping your slices up can also be made to work. |
Is it type of plot still possible? As of matplotlib v3, it seems there no proper way to handle this |
It should work, but without a code example to demonstrate the problem, I
can't help you further.
β¦On Tue, Jul 30, 2019 at 9:50 AM Chao Gao ***@***.***> wrote:
3D don't support zdir = 'x' ????
https://gc13141112.github.io/test/test.png <http://url>
β
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3919?email_source=notifications&email_token=AACHF6AAJF4IXGLEZ7WUSEDQCBBMHA5CNFSM4AZAHIM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3EA6VQ#issuecomment-516427606>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACHF6HPQTGQUKBNNLMFLVTQCBBMHANCNFSM4AZAHIMQ>
.
|
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
Is it type of plot still possible? As of matplotlib v3, it seems there no proper way to handle this |
yes, we need a better way to solve make 3 slices plots on the same figure. |
Relabeling the reason for closure as "can't fix", as this is a renderer issue. However, plotting slices can be done by plotting each quadrant of the slice around the intersection separately. Here's an example (which could probably be made more compact but demonstrates the concept): import matplotlib.pyplot as plt
import numpy as np
def plot_quadrants(ax, slice_data, fixed_coord, coord_val, colormap, shape, min_val, max_val):
half_shape = (shape[1] // 2, shape[2] // 2)
quadrants = [
slice_data[:half_shape[0], :half_shape[1]],
slice_data[:half_shape[0], half_shape[1]:],
slice_data[half_shape[0]:, :half_shape[1]],
slice_data[half_shape[0]:, half_shape[1]:]
]
for i, quad in enumerate(quadrants):
if fixed_coord == 'x':
Y, Z = np.mgrid[0:half_shape[0], 0:half_shape[1]]
X = coord_val * np.ones_like(Y)
Y_offset = (i // 2) * half_shape[0]
Z_offset = (i % 2) * half_shape[1]
ax.plot_surface(X, Y + Y_offset, Z + Z_offset, rstride=1, cstride=1, facecolors=colormap((quad-min_val)/(max_val-min_val)), shade=False)
elif fixed_coord == 'y':
X, Z = np.mgrid[0:half_shape[0], 0:half_shape[1]]
Y = coord_val * np.ones_like(X)
X_offset = (i // 2) * half_shape[0]
Z_offset = (i % 2) * half_shape[1]
ax.plot_surface(X + X_offset, Y, Z + Z_offset, rstride=1, cstride=1, facecolors=colormap((quad-min_val)/(max_val-min_val)), shade=False)
elif fixed_coord == 'z':
X, Y = np.mgrid[0:half_shape[0], 0:half_shape[1]]
Z = coord_val * np.ones_like(X)
X_offset = (i // 2) * half_shape[0]
Y_offset = (i % 2) * half_shape[1]
ax.plot_surface(X + X_offset, Y + Y_offset, Z, rstride=1, cstride=1, facecolors=colormap((quad-min_val)/(max_val-min_val)), shade=False)
def plot_3D_array_slices(array):
colormap = plt.cm.YlOrRd
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
min_val = array.min()
max_val = array.max()
x_slice = array[array.shape[0]//2, :, :]
y_slice = array[:, array.shape[1]//2, :]
z_slice = array[:, :, array.shape[2]//2]
plot_quadrants(ax, x_slice, 'x', array.shape[0]//2, colormap, array.shape, min_val, max_val)
plot_quadrants(ax, y_slice, 'y', array.shape[1]//2, colormap, array.shape, min_val, max_val)
plot_quadrants(ax, z_slice, 'z', array.shape[2]//2, colormap, array.shape, min_val, max_val)
plt.show()
n_pts = 100
r_square = (np.mgrid[-1:1:1j*n_pts, -1:1:1j*n_pts, -1:1:1j*n_pts]**2).sum(0)
plot_3D_array_slices(r_square) |
Thanks @scottshambaugh! I think this would be good as a gallery example. There were some indices mixed up (noticed when using different shapes for the dimensions). Below is a corrected version, which also simplifies the
|
That is cleaner, full disclosure I had chatgpt do my example so I'm not surprised it messed up indexing! Agreed it'd make a nice gallery example, I can whip that up. |
Is it possible to create plots like the one below with matplotlib? If not, would it be difficult to add support for such plots in the mplot3d backend?
I know that such plots can be created with VTK but VTK is still limited to python 2 π
The text was updated successfully, but these errors were encountered: