2015-01-17 3 views
0

파이썬의 matplotlib 라이브러리를 사용하여 가로 막 대형 차트를 플로팅하는 코드를 작성했습니다.Python MatPlotlib barchart- 크기 조정 폭

내 목표는 막 대형 차트의 너비를 조정하는 것이지만 원점으로부터의 거리는 동일하게 유지해야합니다 (5.6). 요컨대, 내 의도는 길이를 동일하게 유지하면서 너비 측면에서 크기를 다듬는 것입니다. 나는 subplots를 사용하여 주어진 예제를 이해할 수 없었다.

여기에 코드입니다 : 내가 3 막대 그래프를 그려왔다

import matplotlib.pyplot as plt;plt.rcdefaults() 
from numpy.random import rand 
from numpy import arange 
import numpy as np 

data = np.genfromtxt('C:\\programming\\Python27\\libra_graphs\\File\\histogram.csv',delimiter=',') 
diff = 0 
time_lst = [] 
for row in data: 
    if not np.isnan(row[7]): 
     diff = row[7]-diff 
time_lst.append(diff) 

print time_lst,len(time_lst) 
y_pos = np.arange(len(time_lst)) 
print y_pos 
val = np.array(diff) 
print val 

plt.barh(y_pos, val,align='center',height = 0.5 ,color='r',alpha=0.5) 
plt.yticks(y_pos) 

plt.xlabel('Time(seconds)') 
plt.title('Job Execution LIBRA') 

plt.show() 
+2

데이터 파일이 없으므로 의미가 명확하지 않습니다. 이미지를 업로드하고 주석을 추가하여 원하는 것을 보여줄 수 있습니까? –

답변

-1

하고, 문제가 해결 된 것입니다.

import matplotlib.pyplot as plt;plt.rcdefaults() 
from numpy.random import rand 
from numpy import arange 
import numpy as np 

def libra_execution_time(): 
    data = np.genfromtxt('C:\\programming\\Python27\\libra_graphs\\File\\histogram.csv',delimiter=',') 

    hash_diff,key_diff,binary_diff = 0,0,0 

    hash_time_lst,key_time_lst,binary_time_lst = [],[],[] 

    for row in data: 
     if not np.isnan(row[7]): 
      hash_diff = row[7]-hash_diff 
    hash_time_lst.append(hash_diff) 

    for row in data: 
     if not np.isnan(row[8]): 
      key_diff = row[8]-key_diff 
    key_time_lst.append(key_diff) 

    for row in data: 
     if not np.isnan(row[9]): 
      binary_diff = row[9]-binary_diff 
    binary_time_lst.append(binary_diff) 

    print "#Hash Partitioner--->" ,hash_time_lst,len(hash_time_lst) 
    print "#Key Field Partitioenr--->", key_time_lst,len(key_time_lst) 
    print "#Binary Partitioner--->",binary_time_lst,len(binary_time_lst) 


    #x_lst = (hash_time_lst + key_time_lst + binary_time_lst) 
    #print x_lst 
    job_time = {"Hash Time":hash_time_lst,"Key_Time":key_time_lst,"Binary Time":binary_time_lst} 
    print job_time 
    print job_time.keys(),job_time.values() 

    y_pos = np.arange(len(job_time.values())) 
    print "Y position",y_pos 
    val = np.array(job_time.values()) 
    print val 


    plt.barh(y_pos,val ,align='center',height = 0.5 ,color=('r','y','g')) 
    plt.yticks(y_pos,job_time.keys()) 

    plt.xlabel('Time(seconds)') 
    plt.ylabel('Performance--->') 
    plt.title('Job Execution LIBRA') 

    plt.show() 

libra_execution_time()