0

I make a loop over two cases and for each case I try to make a plot.

for col_name in ['col2','col3']:
    x_min = min(df['col1'].min(), df[col_name].min())
    x_max = max(df['col1'].max(), df[col_name].max())
    plt.xlim([x_min,x_max])
    plt.ylim([x_min,x_max])
    plt.axes().set_aspect('equal')
    plt.scatter(df['col1'], df[col_name])

As a result I get one plot in my IPython notebook. Does anyone know how to overcome this problem?

1

2 Answers 2

3

You need to call figure() more than once.

for col_name in ['col2','col3']:
    plt = figure() #This gives you a new figure to plot in
    x_min = min(df['col1'].min(), df[col_name].min())
    x_max = max(df['col1'].max(), df[col_name].max())
    plt.xlim([x_min,x_max])
    plt.ylim([x_min,x_max])
    plt.axes().set_aspect('equal')
    plt.scatter(df['col1'], df[col_name])
Sign up to request clarification or add additional context in comments.

Comments

1

I would just use two figures if I want them on different windows.

Something like this ought to work.

>>> for i in range(3):
        xAxis = [randint(1, 5) for _ in range(10)]
        plt.figure(1)
        plt.plot(xAxis)
        plt.show()
        xAxis2 = [randint(1, 5) for _ in range(10)]
        plt.figure(2)
        plt.plot(xAxis2)
        plt.show()

It gave me six consecutive figures.

Since, you need a new figure for every iteration, do.

for index, col_name in ['col2','col3']:
    plt.figure(index)
    # Do the plotting.

Comments

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.