0

I'm currently creating scatters plot to represent the spin orientation for a ferromagnetic material, but this changes with time. What I'm trying to do is create the plots in a for loop. I can currently create each of the plots, but I don't know how to store and recall the plots I'm producing.

Ideally, I would like to recall a specific plot later in the document without having to save the plot as an image.

Is this at all possible?

I am currently using SageMath and Jupyter Notebooks.

This is currently my code to produce the scatter plots:

Beta = ellipsis_range(0.05,Ellipsis,0.8,step=0.05)
for i in range(len(Beta)):
    B = Beta[i]

    j = 0
   
    if B<0.85:
        plt.figure(figsize=((9,6)))
        for y in range(1,N+1):
            for x in range(1,N+1):
                if state[j]==1:
                    plt.scatter(x,y,color="red",marker="^")
                if state[j]==-1:
                    plt.scatter(x,y,color="blue",marker="v")
                j = j+1
        plt.title("Spin Distribution for Beta="+str(round(B,2)))
        plt.show()

My eventual goal is to animate these plots.

Thank you in advance!

1 Answers1

0

I have since managed to store my scatter plots as an array!

def spinplot(B,j,N):
    plot = plt.figure(figsize=((9,6)))
    for y in range(1,N+1):
        for x in range(1,N+1):
            if state[j]==1:
                plt.scatter(x,y,color="red",marker="^")
            if state[j]==-1:
                plt.scatter(x,y,color="blue",marker="v")
        j = j+1
    plt.title("Spin Distribution for Beta="+str(round(B,2)))
    return plot

In the original for-loop, I replaced the plotting code with:

j = 0
if B<0.85:
    plots[k] = spinplot(B,j,N)
    plt.close()
k = k+1

I am now trying to animate them. Which I will ideally save as a gif.