VPython 3D Line Plots

For project 3 part 2, you will generate a plot with two independent variables and one dependent variable by adding 3D curves to the same VPython window across multiple runs of ising_model(..).

Below is a code skeleton to get you started.

from visual import display, curve
vpython_3d_line_window = display(title="VPython 3D Line Plot", autocenter=True)
def ising_model(N, totalEnergy, steps, vis=True):
    ...                                                # other initialization
    M = -2*N**2                                        # the magnetization (initial value is -2N²)
    m_vs_simSteps = curve(display=vpython_3d_line_window)  # note we specify the display initialized earlier outside ising_model
    for step in range(steps):
        for trial in range(N**2):
            ...                                        # do N**2 trials, keeping M up to date
        # we want to color the line red when M = +N² and white when M = -N².
        # this means that color(N²) = (1,0,0) and color(-N²) = (1,1,1)
        # so, scale the green and blue components linearly with M
        t = (1-(M/N**2.))/2
        m_vs_simSteps.append(pos=(step, M, totalEnergy), color=(1, t, t))
cs190c/vpython_3d_line_plot.txt · Last modified: 2008/02/28 08:00 (external edit)
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki