Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia PyPlot: plot 3D surface with as face colors the norm of surface gradient

Does anyone know how to plot a 3D surface with Julia's Pyplot with e.g the norm of the surface-gradient as the face color?

Similar to this topic for Python: Color matplotlib plot_surface command with surface gradient

like image 602
René Hiemstra Avatar asked Apr 28 '16 20:04

René Hiemstra


People also ask

How do you plot a 3D surface plot in Python?

We could plot 3D surfaces in Python too, the function to plot the 3D surfaces is plot_surface(X,Y,Z), where X and Y are the output arrays from meshgrid, and Z=f(X,Y) or Z(i,j)=f(X(i,j),Y(i,j)). The most common surface plotting functions are surf and contour. TRY IT!

What function would we use to plot a 3D surface in Matplotlib?

The axes3d present in Matplotlib's mpl_toolkits. mplot3d toolkit provides the necessary functions used to create 3D surface plots. Surface plots are created by using ax. plot_surface() function.

How do you read a 3D surface plot?

A 3D surface plot is a three-dimensional graph that is useful for investigating desirable response values and operating conditions. A surface plot contains the following elements: Predictors on the x- and y-axes. A continuous surface that represents the response values on the z-axis.


1 Answers

I saw this and I just HAD to make it work. It was almost supported out of the box with Plots.jl, using the PyPlot backend. I just had to swap out for a custom matplotlib shader to apply a different z-matrix.

You'll notice that I'm accessing numpy's gradient function (imported through PyCall), and I'm wrapping the gradient matrix G so that it doesn't get sliced into columns. All in all... much simpler than the python example!

    using Plots; pyplot();
    x = y = LinRange(-5.0, 5.0, 30)
    z = sin(sqrt(Float64[xi^2+yi^2 for xi = x, yi = y]))
    surface(x, y, z, alpha = 0.7)

enter image description here

    using PyCall
    Gx, Gy = Plots.pynb.pymember(:gradient)(z)
    surface(x, y, z, alpha = 0.8, zcolor = wrap(G))

enter image description here

like image 168
Tom Breloff Avatar answered Oct 01 '22 21:10

Tom Breloff