Python/Matplotlib

matplotlib으로 figure창을 여러개 띄우기

uniqueone 2020. 10. 21. 11:26

파이참으로 파이썬 코드 실행 중, figure을 여러개 띄울 때, 창을 닫아야만 그 다음 코드로 진행이 되었다. 이것이 불편해 찾아보니 

import matplotlib.pyplot as plt

x=[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]

y=[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]

for i in range(len(x)):

    plt.figure()

    plt.plot(x[i],y[i])

    # Show/save figure as desired.

    #plt.show()

# Can show all four figures at once by calling plt.show() here, outside the loop.

plt.show()

src: stackoverflow.com/questions/19189488/use-a-loop-to-plot-n-charts-python

에서처럼 그리고자 하는 그림들을 plt.figure() plt.plot(x)으로 각각 그려준 뒤, 맨 마지막에 plt.show()를 1번만 호출하면 전체창이 한꺼번에 띄어졌다.

 

import matplotlib.pyplot as plt

x=[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]

y=[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]

for i in range(len(x)):

    plt.figure()

    plt.plot(x[i],y[i])

    # Show/save figure as desired.

    plt.show()

# Can show all four figures at once by calling plt.show() here, outside the loop.

#plt.show()

처럼 하면 창을 매번 닫아야 그 다음이 진행된다.