2012-11-18 5 views
3

를 사용하여 표시하려면이 선 그림을 얻는 방법 :제대로 나는이 데이터 구조를하기 matplotlib

X axis values: 
delta_Array = np.array([1000,2000,3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) 

    Y Axis values 
    error_matrix = 
[[ 24.22468454 24.22570421 24.22589308 24.22595919 24.22598979 
    24.22600641 24.22601644 24.22602294 24.2260274 24.22603059] 
    [ 28.54275713 28.54503017 28.54545119 28.54559855 28.54566676 
    28.54570381 28.54572615 28.54574065 28.5457506 28.54575771]] 

내가하기 matplotlib와 파이썬

이 코드를 사용하여 선 그림으로 그들을 음모를 어떻게 내가 와서 으로는도를 다음과 같이 평평한 선을 렌더링 (3) = 0 제가

for i in range(error_matrix.shape[0]): 
    plot(delta_Array, error_matrix[i,:]) 

title('errors') 
xlabel('deltas') 
ylabel('errors') 
grid() 
show() 

축의 스케일링된다 같은 문제점이있어 보인다. 그러나 그것을 고치는 방법을 모르겠다. 어떤 아이디어, 제안 곡률을 제대로 표시하는 방법?

enter image description here

답변

3

당신은 쌍둥이 축을 만들 ax.twinx을 사용할 수

import matplotlib.pyplot as plt 
import numpy as np 

delta_Array = np.array([1000,2000,3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) 

error_matrix = np.array(
    [[ 24.22468454, 24.22570421, 24.22589308, 24.22595919, 24.22598979, 24.22600641, 24.22601644, 24.22602294, 24.2260274, 24.22603059], 
    [ 28.54275713, 28.54503017, 28.54545119, 28.54559855, 28.54566676, 28.54570381, 28.54572615, 28.54574065, 28.5457506, 28.54575771]]) 


fig = plt.figure() 
ax = [] 
ax.append(fig.add_subplot(1, 1, 1)) 
ax.append(ax[0].twinx()) 
colors = ('red', 'blue') 

for i,c in zip(range(error_matrix.shape[0]), colors): 
    ax[i].plot(delta_Array, error_matrix[i,:], color = c) 
plt.show() 

수익률

enter image description here

빨간색 선은 error_matrix[0, :]에 해당 error_matrix[1, :] 푸른.

또 다른 가능성은 비율 error_matrix[0, :]/error_matrix[1, :]을 플로팅하는 것입니다.

1

Matplotlib이 올바른 것을 보여줍니다. 두 곡선 모두 같은 y 축척을 원한다면 그 차이가 각 곡선의 차이보다 훨씬 크기 때문에 평평하게됩니다. 다른 y 축척에 신경 쓰지 않는다면, unutbu가 제안한대로하십시오. '

import matplotlib.pyplot as plt 
import numpy as np 

plt.plot(delta_Array, error_matrix[0]/np.max(error_matrix[0]), 'b-') 
plt.plot(delta_Array, error_matrix[1]/np.max(error_matrix[1]), 'r-') 
plt.show() 

functions

을 그리고 그건 그렇고, 당신은 돈 : 당신은 기능 사이의 변화율을 비교하려면

, 나는 각에서 가장 높은 값으로 정상화를 건의 할 것 2D 배열의 차원에서 명시 적이어야합니다. error_matrix[i,:]을 사용하면 error_matrix[i]과 같습니다.

관련 문제