matplotlib 그래프의 테두리 크기를 어떻게 제한합니까?
-
05-07-2019 - |
문제
나는 꽤 큰 그래프를 만들고 있으며, 테두리의 공백은 데이터에서 더 잘 사용할 수있는 많은 픽셀을 차지하고 있습니다. 그래프가 자라면서 국경이 커지는 것 같습니다.
내 그래프 코드의 내장은 다음과 같습니다.
import matplotlib
from pylab import figure
fig = figure()
ax = fig.add_subplot(111)
ax.plot_date((dates, dates), (highs, lows), '-', color='black')
ax.plot_date(dates, closes, '-', marker='_', color='black')
ax.set_title('Title')
ax.grid(True)
fig.set_figheight(96)
fig.set_figwidth(24)
국경의 크기를 줄이는 방법이 있습니까? 어딘가에 국경을 2 인치 정도 유지할 수있는 어딘가에 있을까요?
해결책
단일 서브 플롯을 사용하는 것처럼 보이므로 건너 뛸 수 있습니다. add_subplot
그리고 곧바로 가십시오 add_axes
. 이렇게하면 축의 크기 (그림 관련 좌표)를 줄 수 있으므로 그림 내에서 원하는만큼 크게 만들 수 있습니다. 귀하의 경우, 이것은 귀하의 코드가
import matplotlib.pyplot as plt
fig = plt.figure()
# add_axes takes [left, bottom, width, height]
border_width = 0.05
ax_size = [0+border_width, 0+border_width,
1-2*border_width, 1-2*border-width]
ax = fig.add_axes(ax_size)
ax.plot_date((dates, dates), (highs, lows), '-', color='black')
ax.plot_date(dates, closes, '-', marker='_', color='black')
ax.set_title('Title')
ax.grid(True)
fig.set_figheight(96)
fig.set_figwidth(24)
원한다면 매개 변수를 set_figheight
/set_figwidth
직접 figure()
전화.
다른 팁
시도해보십시오 subplots_adjust
API :
subplots_adjust (*args, ** kwargs)
그림 subplots_adjust (왼쪽 = 없음, 하단 = 없음, 오른쪽 = 없음, wspace = none, hspace = none)
kwargs (없음 rc 로의 기본값)로 서브 플롯 파람을 업데이트하고 서브 플롯 위치를 업데이트하십시오.
제휴하지 않습니다 StackOverflow