我编写了一个代码,用python的matplotlib库绘制水平条形图。
我的目标是调整条形图的宽度,但与原点的距离必须保持不变,即5.6。简而言之,我的目的是根据宽度修剪尺寸,保持长度相同。我无法弄清楚使用子图给出的例子。
以下是代码:
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()
答案 0 :(得分:-1)
我绘制了3个条形图,问题已解决。
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()