2014-07-08 6 views
3

로크 곡선을 그려보고 싶습니다.이 코드는 http://scikit-learn.org/stable/auto_examples/plot_roc.html입니다. X 축 눈금 레이블이 "0.0"은 Y와Matplotlib : 레이블 위치에 점을 찍으십시오.

pl.gca().set_yticks([0.2, 0.4, 0.6, 0.8, 1.0]) 
pl.gca().set_xticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0]) 

enter image description here

을 정렬 할 수 있습니다 방법 :하지만 틱 라벨 0.0 두 축에 나타납니다, 내가 직접 레이블을 설정하여 하나 개의 틱 레이블을 제거 -중심선? 레이블은 y 축의 왼쪽 경계선으로 이동되어야하며 y 축의 다른 눈금 레이블과 동일한 수직 위치에서 시작해야합니다.

+0

나는 당신을 이해하지 못한다. 그냥 원하는거야 : pl.gca(). set_yticks ([0.0,0.2, 0.4, 0.6, 0.8, 1.0]) pl.gca(). set_xticks ([0.2, 0.4, 0.6, 0.8, 1.0]) '?? – yoopoo

답변

4

난 당신이 x 축 치기 할 생각 :

#!/usr/bin/env python3 

import matplotlib 
from matplotlib import pyplot as plt 
from matplotlib.ticker import MaxNLocator 

data = range(5) 


fig = plt.figure() 
ax = fig.add_subplot(111) 

ax.plot(data,data) 

ax.xaxis.set_major_locator(MaxNLocator(5, prune='lower')) 
ax.yaxis.set_major_locator(MaxNLocator(4)) 

fig.savefig("1.png") 

enter image description here

편집 :

슬픈하지만 사실 :하기 matplotlib가 교차 축 2D 플롯을 위해 의미되지 않았다. 당신은 확실히 두 축에 대한 제로 왼쪽 박스 모서리에있는 경우 내가 직접 거기에 넣어하는 것이 좋습니다보다 : 여기

#!/usr/bin/env python3 

import matplotlib 
from matplotlib import pyplot as plt 
from matplotlib.ticker import MaxNLocator 

data = range(5) 


fig = plt.figure() 
ax = fig.add_subplot(111) 

ax.plot(data,data) 

ax.xaxis.set_major_locator(MaxNLocator(5, prune='lower')) 
ax.yaxis.set_major_locator(MaxNLocator(4, prune='lower')) 

fig.tight_layout() 

ax.text(-0.01, -0.02, 
     "0", 
     horizontalalignment = 'center', 
     verticalalignment = 'center', 
     transform = ax.transAxes) 

fig.savefig("1.png") 

enter image description here

한 수동 제로 위치를 조정할 수 있습니다.

개인적으로 상황에 따라 x 축이나 y 축을 잘라 내고 행복하게 처리합니다.

+0

네, 다른 방법으로, 하나의 눈금 레이블을 정리하는 것입니다. 그러나 y 축 (0)의 첫 번째 눈금 레이블을 x 축 (0.8, ...)의 눈금 레이블과 같은 높이로 어떻게 움직일 수 있습니까? 0 축을 두 축의 원점으로 이동하는 방법은 무엇입니까? –

관련 문제