2014-01-26 1 views
1

저는 학생을위한 함수를 그리기 때문에 이미지의 중심에 축을 그려 넣었습니다. 그러나 x-ceil (x)과 같은 함수를 그릴 때 y 축은 [-1,1] 만 표시하고 그래프 기능은 없지만 [-6, 6]을 표시하려고합니다. Y axis 나는 공식적인하기 matplotlib의 문서 (이미지, 꽉, 자동차, ...)하지만 아무것도에서 모든 ax.axis 옵션을 시도했다 : 코드Matplotlib을 사용하여 모든 이미지 그림 주위에 중심 축을 어떻게 배치 할 수 있습니까?

#/usr/bin/env python3 
# -*- coding: utf-8 -*- 

import numpy as np 
import matplotlib.pyplot as plt 


fig, ax = plt.subplots() 
x = np.linspace(-6.0, 6.0, 1000) 
pos = np.where(np.abs(np.diff(np.ceil(x))) == 1.0)[0] + 1 
x = np.insert(x, pos, np.nan) 
ax.axis([x[0] - 0.5, x[-1] + 0.5, x[0] - 0.5, x[-1] + 0.5]) 
ax.spines['left'].set_position('center') 
ax.spines['right'].set_color('none') 
ax.spines['bottom'].set_position('center') 
ax.spines['top'].set_color('none') 
ax.spines['left'].set_smart_bounds(True) 
ax.spines['bottom'].set_smart_bounds(True) 
ax.xaxis.set_ticks_position('bottom') 
ax.yaxis.set_ticks_position('left') 
ticks = [] 
for i in range(int(x[0]), int(x[-1] + 1), 1): 
    ticks.append(i) 
ticks.remove(0) 
ax.set_xticks(ticks) 
ax.set_yticks(ticks) 
ax.plot(x, x - np.ceil(x), color='b', linestyle='-', lw=2.0) 
igual = np.arange(-5, 7, 1) 
igual2 = np.arange(-6, 6, 1) 
ax.plot(igual, np.zeros(12, np.int), 'bo', markeredgecolor='b', markerfacecolor='b', 
     lw=2.0, label='_nolegend_') 
ax.plot(igual2, -1 * np.ones(12, np.int), 'bo', markeredgecolor='b', markerfacecolor='w', 
     lw=2.0, label='_nolegend_') 
ax.legend([r'$f(x)=x-\lceil x \rceil$'], loc='lower right') 
ax.annotate(r'$OX$', xy=(x[-1] - .5, 0.25), size=16, color='black') 
ax.annotate(r'$OY$', xy=(0.25, x[-1]), size=16, color='black') 
ax.set_title(r'$Funci\'on\; f(x)=x-\lceil x \rceil$', fontsize=18) 
ax.grid('on') 
plt.show() 

그리고 여기은 이미지입니다. ax.spines['left'] 작품 set_smart_bounds(True) 제거

감사

답변

1

.

변화

ax.spines['left'].set_smart_bounds(True)
에 :
ax.spines['left']

관련 문제