2017-10-27 1 views
0

내가 만든 그림의 형식을 지정하려고합니다. 종횡비를 설정하려고 시도했지만 종횡비 호출을 포함하거나 ax.set_aspect()를 사용할 때마다 평평한 숫자가됩니다.matplotlib, python 3.6, 평평한 도형의 가로 세로 비율 설정 문제

당신이 당신의 x 축 범위가 ~ y 축에 대한 범위보다 더 큰 300X 경우 예상 밖의 무엇
fig, ax = plt.subplots(1, 1) 
plt.rcParams["font.family"] = 'Calibri' 

ax.set(xlim=[415, 700], ylim=[0,1.01], aspect=1) 

ax.set_xlabel('Wavelength (nm)') 
ax.set_ylabel('Normalized Reflectance (a.u.)') 

_ = ax.plot(x_lambda[0], y_refl_norm[0], marker='', linestyle='-', color='m') 
_ = ax.plot(x_lambda[1], y_refl_norm[1], marker='', linestyle='-', color='b') 
_ = ax.plot(x_lambda[2], y_refl_norm[2], marker='', linestyle='-', color='c') 
_ = ax.plot(x_lambda[3], y_refl_norm[3], marker='', linestyle='-', color='g') 
_ = ax.plot(x_lambda[4], y_refl_norm[4], marker='', linestyle='-', color='y') 
_ = ax.plot(x_lambda[5], y_refl_norm[5], marker='', linestyle='-', 
color='orange') 
_ = ax.plot(x_lambda[6], y_refl_norm[6], marker='', linestyle='-', color='r') 

ax.legend(('30 degrees', '35 degrees', '40 degrees', '45 degrees', '50 
degrees', '55 degrees', '60 degrees'), loc='lower left', fontsize='x-small', 
frameon='True', facecolor='navajowhite', framealpha=0.95) 

Without the "aspect=1"

With the "aspect=1"

답변

0

? aspect=1을 사용하면 너비가 너비보다 300x 작은 그림이 제공됩니다.

이 간단한 예를 보자
import matplotlib.pylab as pl 

pl.figure() 
pl.subplot(231, aspect=1) 
pl.fill_between([0,1],[0,0],[1,1]) 
pl.xlim(0,10) 
pl.ylim(0,10) 

pl.subplot(232, aspect=1) 
pl.fill_between([0,1],[0,0],[1,1]) 
pl.xlim(0,10) 
pl.ylim(0,5) 

pl.subplot(233, aspect=1) 
pl.fill_between([0,1],[0,0],[1,1]) 
pl.xlim(0,10) 
pl.ylim(0,1) 

pl.subplot(234) 
pl.fill_between([0,1],[0,0],[1,1]) 
pl.xlim(0,10) 
pl.ylim(0,10) 

pl.subplot(235) 
pl.fill_between([0,1],[0,0],[1,1]) 
pl.xlim(0,10) 
pl.ylim(0,5) 

pl.subplot(236) 
pl.fill_between([0,1],[0,0],[1,1]) 
pl.xlim(0,10) 
pl.ylim(0,1) 

의 x의 범위는 상기 X 대 Y 축 종횡비를 유지하기 위해 정사각형도 끝낼는 Y의 범위와 동일하다

등가 (검정 블록 = 사각형). y 범위가 x 범위의 절반이면 가로 세로 비율을 유지하기 위해 높이가 너비의 절반이됩니다.

경우에 따라 y 축을 읽기 쉽게 유지하기 위해 veeeeeery를 폭넓게 만들고 싶지 않다면 유일한 해결 방법은 1과 같지 않은 종횡비를 사용하는 것입니다.

enter image description here

+1

감사합니다. 나는 "aspect = 1"이 의미하는 바를 정말로 오해 한 것 같지만, 인쇄 된 그림의 종횡비보다는 데이터의 측면이라는 것이 훨씬 더 의미가 있습니다. – yixingking

+0

축의 종횡비가 잘못됨 * – yixingking

+0

그림의 종횡비를 설정하기가 쉽습니다 (예 : https://stackoverflow.com/questions/332289/how-do-you-change-the-size-of-figures-drawn-with-matplotlib – Bart

관련 문제