1

Is there any Python library/function in order to print in 3D the function "weight"

weight(x,y,z) = x**(y*z) + y**(x*z) + z**(x*y)

with Python and Matplotlib ?

Here is already an interesting link How to plot a 3D density map in python with matplotlib but it shows a density instead of a weight for distributed coordinates X Y Z, for example from -5 to +5 with regular steps 0.1 (where solutions for the weight exists in real numbers).

I am just playing around with some math functions and wanted to show this for teaching purpose, no immediate use identified.

Update 1: achievement so far with plotly

enter image description here

"""
release May22 2020
https://plotly.com/python/3d-volume-plots/
"""
import plotly.graph_objects as go
import numpy as np

#X, Y, Z = np.mgrid[-5:5:40j, -5:5:40j, -5:5:40j]
X, Y, Z = np.mgrid[ 0.01:2:40j, 0.01:2:40j, 0.01:2:40j]
#
# pascal dagsi surfaces
#vol=(X**(Y*Z)) + (Y**(X*Z)) + (Z**(X*Y))
#vol=(X**(Y+Z)) + (Y**(X+Z)) + (Z**(X+Y))
#vol=(X**(Y+Z)) * (Y**(X+Z)) * (Z**(X+Y))
vol=(X**(Y*Z)) * (Y**(X*Z)) * (Z**(X*Y))

fig = go.Figure(data=go.Volume(
    x=X.flatten(),
    y=Y.flatten(),
    z=Z.flatten(),
    value=vol.flatten(),
    opacity=0.1,
    isomin=0.02,
    isomax=100,
    surface_count=22,
    caps=dict(x_show=False, y_show=False, z_show=False)
    ))
#
fig.show()

Update 2: other variant (iso surface)

"""
release May22 2020
https://plotly.com/python/3d-isosurface-plots/
"""
import plotly.graph_objects as go
import numpy as np
#X, Y, Z = np.mgrid[-5:5:40j, -5:5:40j, -5:5:40j]
#X, Y, Z = np.mgrid[ 0.1:5:40j, 0.1:5:40j, 0.1:5:40j]
X, Y, Z = np.mgrid[ 0.01:2:40j, 0.01:2:40j, 0.01:2:40j]
#
# pascal dagsi surfaces
#values=(X**(Y*Z)) + (Y**(X*Z)) + (Z**(X*Y))
#values=(X**(Y+Z)) + (Y**(X+Z)) + (Z**(X+Y))
#values=(X**(Y+Z)) * (Y**(X+Z)) * (Z**(X+Y))
values=(X**(Y*Z)) * (Y**(X*Z)) * (Z**(X*Y))

fig = go.Figure(data=go.Isosurface(
    x=X.flatten(),
    y=Y.flatten(),
    z=Z.flatten(),
    value=values.flatten(),
    opacity=0.2,
    isomin=0.5,
    isomax=25,
    surface_count=10,
    caps=dict(x_show=False, y_show=False)
    ))
#
fig.show()

enter image description here

Update 3: mayavi works

enter image description here

"""
release May22 2020
pascal dagsi surfaces
"""
import numpy as np
from mayavi import mlab
#
x, y, z = np.ogrid[ 0.01:2:40j, 0.01:2:40j, 0.01:2:40j]
#
#s=(x**(y*z)) + (y**(x*z)) + (z**(x*y))
#s=(x**(y+z)) + (y**(x+z)) + (z**(x+y))
#s=(x**(y+z)) * (y**(x+z)) * (z**(x+y))
s=(x**(y*z)) * (y**(x*z)) * (z**(x*y))

src = mlab.pipeline.scalar_field(s)

mlab.pipeline.iso_surface(src, contours=[0.1, 0.2, 0.5, 1, 11, 1001, 100001], opacity=0.2,colormap='magma',vmin=0.01,vmax=0.99)

mlab.axes()
mlab.show()
2
  • 2
    The answer in the link you provided looks very much like you could plot any scalar field with it, not just densities, which would be a very weird confinement tbh Commented May 14, 2020 at 21:50
  • Thanks for the hint!. See post update. Commented May 22, 2020 at 7:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.