2017-05-10 11 views
0

IPython Notebook을 사용하고 있습니다. 같은 그림에 여러 줄거리가 있습니다. 다른 축 매개 변수에 대해 pyplot을 여러 번 다시 그리는 방법

Cases x-axis y-axis 
1  non-log non-log 
2  non-log log 
3  log  non-log 
4  log  log 

이런 쉬운 방법이 있나요 : 나는 다음과 같은 네 가지 경우에, 즉 서로 다른 축 매개 변수를 사용하여 이러한 플롯을 표시해야합니다

#many lines of code for generating bunch of plots 
plt.show() 

#figure shown with non-log axis 

ax.set_yscale('log') 
plt.show() 

#figure shown with log y-axis  

ax.set_xscale('log') 
plt.show() 

#figure shown with log x-axis and log y-axis 

답변

1

plt.show()이 그림 (들)을 보여줍니다가와 나중에 그들을 버리십시오. 그것은 스크립트에서 여러 번 사용하기위한 것이 아닙니다.

함수에서 플로팅을 수행하고 인수에 따라 옵션을 사용하면 다른 그림을 만들 수 있습니다. 다음은 4 가지 경우에 대한 수치를 작성합니다 :

import matplotlib.pyplot as plt 
import numpy as np 

x = np.logspace(0,3, 250) 
y = .4*x 

def plot(x,y,logx=False, logy=False): 
    fig, ax = plt.subplots() 
    if logy: ax.set_yscale('log') 
    if logx: ax.set_xscale('log') 
    ax.plot(x,y) 


plot(x,y) 
plot(x,y, True, False) 
plot(x,y, False, True) 
plot(x,y, True, True) 

plt.show()