파이썬에서 그래프를 여러개 그려야할 때
(1) 하나의 창에 여러개의 그래프를 그리는 방법과
(2) 각각의 그래프를 각각의 창에 그리는 경우가 있을 수 있다.
1. 하나의 창에 여러개의 그래프를 그리는 방법 : subplot
import matplotlib.pyplot as plt
import numpy as np
csvData = np.loadtxt(Filename, delimiter=',' )
timeData = csvData[0:len(csvData)]
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
ax1.plot(timeData, label='sound data')
ax1.legend()
timeData = (timeData - np.mean(timeData))/maxSampleValue
ax2.plot(timeData, label='normalized sound data')
ax2.legend()
fig.show()
2. 각각의 그래프를 각각의 창에 그리는 경우
방법 #1
x = np.arange(5)
y = np.exp(x)
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(x, y)
z = np.sin(x)
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.plot(x, z)
w = np.cos(x)
ax1.plot(x, w) # can continue plotting on the first axis
방법 #2
x = arange(5)
y = np.exp(x)
plt.figure(0)
plt.plot(x, y)
z = np.sin(x)
plt.figure(1)
plt.plot(x, z)
w = np.cos(x)
plt.figure(0) # Here's the part I need
plt.plot(x, w)
Edit: Note that you can number the plots however you want (here, starting from 0) but if you don't provide figure with a number at all when you create a new one, the automatic numbering will start at 1 ("Matlab Style" according to the docs).
출처: <https://stackoverflow.com/questions/6916978/how-do-i-tell-matplotlib-to-create-a-second-new-plot-then-later-plot-on-the-o>
피드 구독하기:
댓글 (Atom)
람다 표현식 (Lambda expression)
람다 표현식(Lambda expression) 람다 표현식으로 함수를 정의하고, 이를 변수에 할당하여 변수를 함수처럼 사용한다. (1) 람다 표현식 lambda <매개변수> : 수식 ※ 람다식을 실행하...
-
데이터 과학자가 알아야 할 5가지 클러스터링 알고리즘 February 26,2018 클러스터링은 데이터 포인트의 그룹화와 관련된 머신러닝 기술입니다. 데이터 포인트 집합이 주어지면 클러...
-
Speech Processing for Machine Learning: Filter banks, Mel-Frequency Cepstral Coefficients (MFCCs) and What's In-Between 출처: < http:...
-
영교차점(zero-crossing) 찾기 (파이썬) a = [1, 2, 1, 1, -3, -4, 7, 8, 9, 10, -2, 1, -3, 5, 6, 7, -10] 일 때, In[61]: z = np.where(np.diff(np.sign(...
댓글 없음:
댓글 쓰기