2013-11-01 5 views
3

3 열이있는 데이터 테이블이 있는데,이 테이블은 다채로운 2D 플롯의 첫 번째 열을 기준으로 세 번째 열을 플롯합니다.플롯의 원점 변경

x,y,z = np.loadtxt('output_overlap.dat').T #Transposed for easier unpacking 
nrows, ncols = final_step_j-1, final_step_k-1 
grid = z.reshape((nrows, ncols)) 
plt.imshow(grid, extent=(x.min(), x.max(), y.max(), y.min()), 
      interpolation='nearest', 
      cmap='binary') 
fig1 = plt.gcf() 
plt.colorbar() 
plt.xlabel('m1') 
plt.ylabel('m2') 
plt.draw() 
fig1.savefig('test.pdf', dpi=100) 
close('all') 

나에게 다음과 같은 플롯을 제공합니다 : 올 https://dl.dropboxusercontent.com/u/31460244/test.png

다음 표 즉

4.0 4.0 0.313660827978 
4.0 5.0 0.365348418405 
4.0 6.0 0.423733120134 
5.0 4.0 0.365348418405 
5.0 5.0 0.439599930621 
5.0 6.0 0.525083754405 
6.0 4.0 0.423733120134 
6.0 5.0 0.525083754405 
6.0 6.0 0.651536351379 

에 대한 예를 들어 다음 코드를 사용합니다. 이제 제 질문은 Y 축에서 데이터를 표시하는 순서를 어떻게 바꿀 수 있습니까? 나는 원점에 요점 (4,4)을 갖고 싶다.

I가

plt.imshow(grid, extent=(x.min(), x.max(), y.max(), y.min()) 

변경 시도 : 그것은 그리드의 숫자가 아니라 실제 데이터를 변경 않습니다

plt.imshow(grid, extent=(x.min(), x.max(), y.min(), y.max()) 

. 이것은 해결책이 아닙니다. 아무도 나 한테 도움을 줄 수 없어?

답변

7

범위는 데이터에 이러한 코너 좌표를 할당하기 만하면 기본 데이터의 순서를 변경하지 않습니다.

imshow이에 대한 origin 키워드를 가지고, 참조 :

a = np.array([0.313660827978, 0.365348418405, 0.423733120134, 
       0.365348418405, 0.439599930621, 0.525083754405, 
       0.423733120134, 0.525083754405, 0.651536351379]).reshape(3,3) 

extent = [4,6,4,6] 

fig, axs = plt.subplots(1,2) 

axs[0].imshow(a, extent=extent, interpolation='none') 
axs[1].imshow(a, origin='lower', extent=extent, interpolation='none') 

enter image description here

는 또한 배열의 축을 미러링 np.flipudnp.fliplr을 고려할 수 있습니다. 그러나 필자가 개인적으로 원한다면 imshow로 원점을 설정하는 것이 더 좋습니다.

+0

imshow에 원점 = 'lower'를 추가하면 완벽하게 작동합니다. 감사! – Rotail

관련 문제