Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Okay, just to illustrate the non-Jmol approach I had in mind:


# matplotlib-based version
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
var("x y alpha")

Fp1_11 = 5*x*alpha^2+3*y
Fp1_12 = 2*(x+y)^(1/3)*cos(alpha)
Fp1_21 = sin(x*y+alpha)
Fp1_22 = (x^2+y^2*alpha)^(1/2)
fns = [Fp1_11, Fp1_12, Fp1_21, Fp1_22]

@interact
def fplot(alpha=(0.0, 1.0)):
    fig = plt.figure()
    for i, fn in enumerate(fns, 1):
        ax = fig.add_subplot(2,2,i,projection='3d')
        xx = np.linspace(-20, 20, 50)
        yy = xx
        X, Y = np.meshgrid(xx, yy)
        # the next line is ugly, but it works
        Z = np.array(list(np.float(fn.subs(x=x_,y=y_,alpha=alpha)) for x_,y_ in zip(X.flatten(), Y.flatten())))
        Z = Z.reshape(X.shape)
        ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
        cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
        cset = ax.contour(X, Y, Z, zdir='x', offset=-20)
        cset = ax.contour(X, Y, Z, zdir='y', offset=20)
        ax.set_xlabel('X')
        ax.set_xlim3d(-20, 20)
        ax.set_ylabel('Y')
        ax.set_ylim3d(-20, 20)
        ax.set_zlabel('Z')
        ax.set_zlim3d(-100, 100)
    plt.savefig("fplot.png")

gives something like

image description

where when you adjust alpha the plots change. No rotation, and it's not that speedy, but it's functional.

Okay, just to illustrate the non-Jmol approach I had in mind:


# matplotlib-based version
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
var("x y alpha")

Fp1_11 = 5*x*alpha^2+3*y
Fp1_12 = 2*(x+y)^(1/3)*cos(alpha)
Fp1_21 = sin(x*y+alpha)
Fp1_22 = (x^2+y^2*alpha)^(1/2)
fns = [Fp1_11, Fp1_12, Fp1_21, Fp1_22]

@interact
def fplot(alpha=(0.0, 1.0)):
    fig = plt.figure()
    for i, fn in enumerate(fns, 1):
        ax = fig.add_subplot(2,2,i,projection='3d')
        xx = np.linspace(-20, 20, 50)
        yy = xx
        X, Y = np.meshgrid(xx, yy)
        # the next line is ugly, but it works
        Z = np.array(list(np.float(fn.subs(x=x_,y=y_,alpha=alpha)) for x_,y_ in zip(X.flatten(), Y.flatten())))
        Z = Z.reshape(X.shape)
        ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
        cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
        cset = ax.contour(X, Y, Z, zdir='x', offset=-20)
        cset = ax.contour(X, Y, Z, zdir='y', offset=20)
        ax.set_xlabel('X')
        ax.set_xlim3d(-20, 20)
        ax.set_ylabel('Y')
        ax.set_ylim3d(-20, 20)
        ax.set_zlabel('Z')
        ax.set_zlim3d(-100, 100)
    plt.savefig("fplot.png")

gives something like

image description

where when if you adjust alpha the plots change. No rotation, and it's not that speedy, but it's functional.

Okay, just to illustrate the non-Jmol approach I had in mind:


# matplotlib-based version
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
var("x y alpha")

Fp1_11 = 5*x*alpha^2+3*y
Fp1_12 = 2*(x+y)^(1/3)*cos(alpha)
Fp1_21 = sin(x*y+alpha)
Fp1_22 = (x^2+y^2*alpha)^(1/2)
fns = [Fp1_11, Fp1_12, Fp1_21, Fp1_22]

@interact
def fplot(alpha=(0.0, 1.0)):
    fig = plt.figure()
    for i, fn in enumerate(fns, 1):
        ax = fig.add_subplot(2,2,i,projection='3d')
        xx = np.linspace(-20, 20, 50)
        yy = xx
        X, Y = np.meshgrid(xx, yy)
        # the next line is ugly, but it works
        Z = np.array(list(np.float(fn.subs(x=x_,y=y_,alpha=alpha)) for x_,y_ in zip(X.flatten(), Y.flatten())))
        Z = Z.reshape(X.shape)
        ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
        cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
        cset = ax.contour(X, Y, Z, zdir='x', offset=-20)
        cset = ax.contour(X, Y, Z, zdir='y', offset=20)
        ax.set_xlabel('X')
        ax.set_xlim3d(-20, 20)
        ax.set_ylabel('Y')
        ax.set_ylim3d(-20, 20)
        ax.set_zlabel('Z')
        ax.set_zlim3d(-100, 100)
    plt.savefig("fplot.png")

gives something like

image description

where if you adjust alpha the plots change. No rotation, and it's not that speedy, but it's functional.functional. Also note that I didn't bother checking that my limits were sensible, or giving enough space to the ticks, etc.

Okay, just to illustrate the non-Jmol approach I had in mind:


# matplotlib-based version
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
var("x y alpha")

Fp1_11 = 5*x*alpha^2+3*y
Fp1_12 = 2*(x+y)^(1/3)*cos(alpha)
Fp1_21 = sin(x*y+alpha)
Fp1_22 = (x^2+y^2*alpha)^(1/2)
fns = [Fp1_11, Fp1_12, Fp1_21, Fp1_22]

@interact
def fplot(alpha=(0.0, 1.0)):
    fig = plt.figure()
    for i, fn in enumerate(fns, 1):
        ax = fig.add_subplot(2,2,i,projection='3d')
        xx = np.linspace(-20, 20, 50)
        yy = xx
        X, Y = np.meshgrid(xx, yy)
        # the next line is ugly, but it works
        Z = np.array(list(np.float(fn.subs(x=x_,y=y_,alpha=alpha)) for x_,y_ in zip(X.flatten(), Y.flatten())))
        Z = Z.reshape(X.shape)
        ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
        cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
        cset = ax.contour(X, Y, Z, zdir='x', offset=-20)
        cset = ax.contour(X, Y, Z, zdir='y', offset=20)
        ax.set_xlabel('X')
        ax.set_xlim3d(-20, 20)
        ax.set_ylabel('Y')
        ax.set_ylim3d(-20, 20)
        ax.set_zlabel('Z')
        ax.set_zlim3d(-100, 100)
    plt.savefig("fplot.png")

gives something like

image description

where if you adjust alpha the plots change. No rotation, and it's not that speedy, but it's functional. Also note that I didn't bother checking that my limits were sensible, or giving give enough space to the ticks, etc.

Okay, just to illustrate the non-Jmol approach I had in mind:


# matplotlib-based version
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
var("x y alpha")

Fp1_11 = 5*x*alpha^2+3*y
Fp1_12 = 2*(x+y)^(1/3)*cos(alpha)
Fp1_21 = sin(x*y+alpha)
Fp1_22 = (x^2+y^2*alpha)^(1/2)
fns = [Fp1_11, Fp1_12, Fp1_21, Fp1_22]

@interact
def fplot(alpha=(0.0, 1.0)):
    fig = plt.figure()
    for i, fn in enumerate(fns, 1):
        ax = fig.add_subplot(2,2,i,projection='3d')
        xx = np.linspace(-20, 20, 50)
        yy = xx
        X, Y = np.meshgrid(xx, yy)
        # the next line is ugly, but it works
        Z = np.array(list(np.float(fn.subs(x=x_,y=y_,alpha=alpha)) for x_,y_ in zip(X.flatten(), Y.flatten())))
        Z = Z.reshape(X.shape)
        ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
        cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
        cset = ax.contour(X, Y, Z, zdir='x', offset=-20)
        cset = ax.contour(X, Y, Z, zdir='y', offset=20)
        ax.set_xlabel('X')
        ax.set_xlim3d(-20, 20)
        ax.set_ylabel('Y')
        ax.set_ylim3d(-20, 20)
        ax.set_zlabel('Z')
        ax.set_zlim3d(-100, 100)
    plt.savefig("fplot.png")

gives something like

image description

where if you adjust alpha the plots change. No rotation, and it's not that speedy, but it's functional. Also note that I didn't bother checking that my limits were sensible, or give enough space to the ticks, etc.

Okay, just to illustrate the non-Jmol approach I had in mind:


# matplotlib-based version
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
var("x y alpha")

Fp1_11 = 5*x*alpha^2+3*y
5*x+3*y
Fp1_12 = 2*(x+y)^(1/3)*cos(alpha)
(2*(x+y)^(1/3)*cos(alpha)+(1+alpha/10)^((y)))*20
Fp1_21 = sin(x*y+alpha)
Fp1_22 = (x^2+y^2*alpha)^(1/2)
alpha*((x^2+y^2))^(1/2)
fns = [Fp1_11, Fp1_12, Fp1_21, Fp1_22]

@interact
def fplot(alpha=(0.0, 1.0)):
fplot(alpha=(1.0,5)):
    fig = plt.figure()
    fig.subplots_adjust(wspace=0.05, hspace=0.05,left=0.05, right=0.95)
    for i, fn in enumerate(fns, 1):
        ax = fig.add_subplot(2,2,i,projection='3d')
        xx = np.linspace(-20, 20, np.linspace(-10, 10, 50)
        yy = xx
        X, Y = np.meshgrid(xx, yy)
        # the next line is ugly, but it works
        Z = np.array(list(np.float(fn.subs(x=x_,y=y_,alpha=alpha)) for x_,y_ x_, y_ in zip(X.flatten(), Y.flatten())))
        Z = Z.reshape(X.shape)
        ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
        cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
        cset #cset = ax.contour(X, Y, Z, zdir='x', offset=-20)
        cset offset=-10)
        #cset = ax.contour(X, Y, Z, zdir='y', offset=20)
offset=10)
        ax.set_xlabel('X')
        ax.set_xlim3d(-20, 20)
ax.set_xlim3d(-10, 10)
        ax.set_ylabel('Y')
        ax.set_ylim3d(-20, 20)
ax.set_ylim3d(-10, 10)
        ax.set_zlabel('Z')
        ax.set_zlim3d(-100, 100)
    plt.savefig("fplot.png")

gives something like

image descriptionimage description

where if you adjust alpha the plots change. No rotation, and it's not that speedy, but it's functional. Also note that I didn't bother checking that my limits were sensible, or give enough space to the ticks, etc.etc. [Update: looks like I forgot an import. Also some minor edits for aesthetic reasons.]

Okay, just to illustrate the non-Jmol approach I had in mind:


# matplotlib-based version
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
var("x y alpha")

Fp1_11 = 5*x+3*y
Fp1_12 = (2*(x+y)^(1/3)*cos(alpha)+(1+alpha/10)^((y)))*20
Fp1_21 = sin(x*y+alpha)
Fp1_22 = alpha*((x^2+y^2))^(1/2)
fns = [Fp1_11, Fp1_12, Fp1_21, Fp1_22]

@interact
def fplot(alpha=(1.0,5)):
    fig = plt.figure()
    fig.subplots_adjust(wspace=0.05, hspace=0.05,left=0.05, right=0.95)
    for i, fn in enumerate(fns, 1):
        ax = fig.add_subplot(2,2,i,projection='3d')
        xx = np.linspace(-10, 10, 50)
        yy = xx
        X, Y = np.meshgrid(xx, yy)
        # the next line is ugly, but it works
        Z = np.array(list(np.float(fn.subs(x=x_,y=y_,alpha=alpha)) for x_, y_ in zip(X.flatten(), Y.flatten())))
        Z = Z.reshape(X.shape)
        ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
        cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
        #cset = ax.contour(X, Y, Z, zdir='x', offset=-10)
        #cset = ax.contour(X, Y, Z, zdir='y', offset=10)
        ax.set_xlabel('X')
        ax.set_xlim3d(-10, 10)
        ax.set_ylabel('Y')
        ax.set_ylim3d(-10, 10)
        ax.set_zlabel('Z')
        ax.set_zlim3d(-100, 100)
    plt.savefig("fplot.png")

gives something like

image description

where if you adjust alpha the plots change. No rotation, and it's not that speedy, but it's functional. Also note that I didn't bother checking that my limits were sensible, or give enough space to the ticks, etc. [Update: looks like I forgot an import. Also some minor edits for aesthetic reasons.]