내 천체 물리학 인턴십 프로젝트에서 노이즈 맵에 대한 신호를 만들고 있는데, 대신 히트 맵당 하나의 컬러 바를 얻기 위해 다음과 같이 히트 맵별로 3 개의 컬러 바를 얻으므로 서브 플롯에 약간의 문제가 있습니다.
이것은 내 스크립트입니다 (이해할 수 있기를 바랍니다).
# VERIFICATION DE LA CARTE S/N
# convolution_X and convolution_mask_X are arrays
fig10 = plt.subplot(1,3,1)
step1 = convolution_locale - convolution_mask_locale
fig_step1 = plt.imshow(step1, interpolation='nearest')
plt.colorbar()
plt.xlabel("X (arcmin)")
plt.ylabel("Y (arcmin)")
fig10 = plt.subplot(1,3,2)
step2 = convolution_grande - convolution_mask_grande
fig_step2 = plt.imshow(step2, interpolation='nearest')
plt.colorbar()
plt.xlabel("X (arcmin)")
plt.ylabel("Y (arcmin)")
fig10 = plt.subplot(1,3,3)
S_N_map = step1 - step2
fig_S_N_map = plt.imshow(S_N_map, interpolation='nearest')
plt.colorbar()
plt.xlabel("X (arcmin)")
plt.ylabel("Y (arcmin)")
fig10 = plt.savefig(outname10)
어레이에 대한 추가 정보가 필요하십니까?
아이디어가 있으시면 감사합니다!
어떤 컬러 바가 어떤 서브 플롯에 속하는지 알려주지 않기 때문에 코드가 혼란스러워집니다.
matplotlib 객체 지향 접근 방식을 사용하면 여기서 많은 도움이 될 것입니다. Figure 및 서브 플롯 인스턴스를 생성하는 경우 (예 :를 사용하여 plt.subplots()
), 전혀 사용할 필요없이 이러한 각 인스턴스 에서 플로팅 (예 :) ax1.imshow
및 레이블링 (예 :) ax1.set_xlabel
메서드를 호출 할 수 있습니다 plt
. 그런 다음 컬러 바 ( fig10.colorbar()
) 를 생성 할 때 ax
kwarg를 사용하여 옆에 컬러 바를 생성 할 서브 플롯을 지정할 수 있습니다 .
또한 매핑 가능한 객체 (예 :) fig_step1
를에 대한 호출에 제공 fig10.colorbar
하여 올바른 배열이 컬러 바 스케일을 생성하는 데 사용되고 있는지 확인합니다.
import matplotlib.pyplot as plt
import numpy as np
# Some fake data
outname10 = 'test.png'
convolution_locale = np.random.rand(250,250)
convolution_mask_locale = np.random.rand(250,250)
convolution_grande = np.random.rand(250,250)
convolution_mask_grande = np.random.rand(250,250)
# use a nice colormap
plt.viridis()
# Create the figure and subplot instances
fig10, (ax1, ax2, ax3) = plt.subplots(1,3)
step1 = convolution_locale - convolution_mask_locale
fig_step1 = ax1.imshow(step1, interpolation='nearest')
fig10.colorbar(fig_step1,ax=ax1)
ax1.set_xlabel("X (arcmin)")
ax1.set_ylabel("Y (arcmin)")
step2 = convolution_grande - convolution_mask_grande
fig_step2 = ax2.imshow(step2, interpolation='nearest')
fig10.colorbar(fig_step2,ax=ax2)
ax2.set_xlabel("X (arcmin)")
ax2.set_ylabel("Y (arcmin)")
S_N_map = step1 - step2
fig_S_N_map = ax3.imshow(S_N_map, interpolation='nearest')
fig10.colorbar(fig_S_N_map,ax=ax3)
ax3.set_xlabel("X (arcmin)")
ax3.set_ylabel("Y (arcmin)")
# Create space for labels between subplots
fig10.set_tight_layout(True)
fig10.savefig(outname10)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다