2014-11-03 1 views
0

에서하지 STARTTIME에서 막대 나 숫자 플롯 예컨대 제로

starTime1 = 1.5 
starTime2 = 3 
starTime3 = 2.3 

을하고 난 세 바있는 이름, 예를 들면 horizantal : BAR1 바 2 제가 가진

"X 왈져 "scale = 24 hours (range0,24)

따라서"startTime "값에서 막대를 플로팅하는 방법, 0이 아닌 막대를 플로팅하는 방법.

내 코드가 있습니다. 변수 "순위"는 막대의 종료 시간입니다.

import csv 
import datetime 
import time 
import numpy as np 
import matplotlib.pyplot as plt 
import pylab 
from matplotlib.ticker import MaxNLocator 

numCp = 10 
cpNames = [data[4][6], data[5][6], data[6][6], data[7][6], 
     data[8][6], data[9][6], data[10][6], data[11][6], 
     data[12][6], data[13][6]] 
testMeta = ['UOL/sec' , 'UOL/sec', 'UOL/sec', 'UOL/sec', 'UOL/sec', 'UOL/sec',  'UOL/sec', 'UOL/sec', 'UOL/sec', 'UOL/sec' ] 
scores = [data[4][4], data[5][4], data[6][4], data[7][4], data[8][4], 
     data[9][4], data[10][4], data[11][4], data[12][4], data[13][4]] 
rankings = intAllCpMin 



fig, ax1 = plt.subplots(figsize=(9, 7)) #height and width of chart 
plt.subplots_adjust(left=0.115, right=0.88) 
fig.canvas.set_window_title('Eldorado K-8 Fitness Chart') 
pos = np.arange(numCp)+0.5 # Center bars on the Y-axis ticks 
rects = ax1.barh(pos, rankings, align='center', height=0.5, color='m') 

ax1.axis([0, 100, 0, 10]) # to display all CP bars correctly change last number on  numbers of CP 
pylab.yticks(pos, cpNames) 
ax1.set_title('Non Functional Test Results') 
plt.text(50, -0.5, 'Hours', 
    horizontalalignment='center', size='small') 

ax2 = ax1.twinx() 
ax2.plot([totalRunTime, totalRunTime], [0, 5], 'white', alpha=0.1) #width of X 
ax2.xaxis.set_major_locator(MaxNLocator(totalRunTime)) 
xticks = pylab.setp(ax2, xticklabels=[lowestStartTime," "," "," "," "," ",  higherStartTime]) 
ax2.xaxis.grid(True, linestyle='--', which='major', color='grey', 
alpha=0.25) 

def withnew(i, scr): 
    if testMeta[i] != '': 
     return '%s\n' % scr 
    else: 
     return scr 

scoreLabels = [withnew(i, scr) for i, scr in enumerate(scores)] 
scoreLabels = [i+j for i, j in zip(scoreLabels, testMeta)] 
ax2.set_yticks(pos) 
ax2.set_yticklabels(scoreLabels) 
ax2.set_ylim(ax1.get_ylim()) 


ax2.set_ylabel('Test Scores') 

suffixes = sorted([str(data[4][14][5:12]), data[5][14][5:12], data[6][14][5:12], data[7][14][5:12], data[8][14][5:12], 
       data[9][14][5:12],data[10][14][5:12], data[11][14][5:12], data[12][14] [5:12], data[13][14][5:12]]) 


    width = int(rect.get_width()) 

    rankStr = "" 
    if (width < 2):  # The bars aren't wide enough to print the ranking inside 
     xloc = width+0.1 # Shift the text to the right side of the right edge 
     clr = 'black'  # Black against white background 
     align = 'left' 
     rankStr += suffixes[1] + " Total Run Time" 
    else: 
     xloc = 0.50*width # Shift the text to the left side of the right edge 
     clr = 'white'  # White on magenta 
     align = 'center' 
     rankStr += suffixes[1] + " Total Run Time" 

     yloc = rect.get_y()+rect.get_height()/2.0 
     ax1.text(xloc, yloc, suffixes[1], horizontalalignment=align, 
     verticalalignment='center', color=clr, weight='bold') 


plt.show() 
+0

. '데이터'가 누락되었습니다. – freshtop

답변

0

당신은 줄의 시작 위치를 변경 barhleft 키워드 (또는 수직 막대의 bottom 키워드)를 사용할 수 있습니다. 하지만 막대 길이에서 같은 양을 빼야합니다.

예 :이 실행되지 않습니다

pylab.barh([1,2,3], [10,20,30], left=20) 
+0

대단히 감사합니다 !!! –