数据源自文章“Fast graph mining with HBase”
代码如下
import numpy as np
import matplotlib.pyplot as plt
size = 4
x = np.arange(size)
UNICORN = np.array([33,222,603,2697])
PEGASUS = np.array([66,566,3094,28559])
HBMV_E= np.array([690,14111,0,0])
HBMV_DL = np.array([1379,34418,0,0])
##柱宽度,以及位置定义
total_width, n = 0.6, 4
width = total_width / n
x = x - (total_width - width) / 2
index = np.arange(size)
##set tick direction , must be set at the begin
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
##y轴范围,设置log坐标
plt.ylim(1e1,1e5)
plt.yscale('log')
plt.bar(x, UNICORN, width=width, label='UNICORN',fc='y')
plt.bar(x + width, PEGASUS, width=width, label='PEGASUS',fc='b')
plt.bar(x + 2 * width, HBMV_E, width=width, label='HBMV-E')
plt.bar(x + 3 * width, HBMV_DL, width=width, label='HBMV-DL')
plt.xticks(index,('LinkedIn','Twitter','YahooWeb','Kronecher'))
plt.ylabel("Running time (Sec)",fontsize=13)
plt.legend()
plt.show()
特别要注意的是要设置刻度朝内必须在plt开头设置,在后面设置无效
效果如下
2.曲线图
通过读取excel数据绘制曲线图,代码如下
#plot data picture from a excel
import numpy as np
import matplotlib.pyplot as plt
import xlrd
#open a workbook
workbook = xlrd.open_workbook(r'C:myPythonCodetest1.xlsx')
worksheets = workbook.sheet_names()
mySheet=workbook.sheets()[0]
#getdata
RG1 = mySheet.col_values(0)
#print(RG)
exempt1 = mySheet.col_values(1)
#print(exempt)
RG1.pop(0)
exempt1.pop(0)
RG2=mySheet.col_values(3)
exempt2=mySheet.col_values(4)
fig1=plt.figure(1)
plt.title("the first ")
plt.plot(RG1,exempt1,c='red')
plt.show()
RG2.pop(0)
exempt2.pop(0)
fig2=plt.figure(2)
plt.title("the second ")
plt.plot(RG2,exempt2,c='green')
plt.show()
fig1.savefig("spectrum1.png")
fig1.savefig("spectrum2.png")
将两张图绘制在一起
#plot data picture from a excel
import numpy as np
import matplotlib.pyplot as plt
import xlrd
#open a workbook
workbook = xlrd.open_workbook(r'C:myPythonCodetest1.xlsx')
worksheets = workbook.sheet_names()
mySheet=workbook.sheets()[0]
#getdata
RG1 = mySheet.col_values(0)
#print(RG)
exempt1 = mySheet.col_values(1)
#print(exempt)
RG1.pop(0)
exempt1.pop(0)
RG2=mySheet.col_values(3)
exempt2=mySheet.col_values(4)
# fig1=plt.figure(1)
# plt.title("b0")
# plt.plot(RG1,exempt1,c='red')
# plt.xlabel("λ(nm)")
# plt.ylabel("exempt")
# plt.show()
RG2.pop(0)
exempt2.pop(0)
# fig2=plt.figure(2)
# plt.title("299")
# plt.plot(RG2,exempt2,c='green')
# plt.xlabel("λ(nm)")
# plt.ylabel("exempt")
# plt.show()
fig3=plt.figure(3)
plt.title("b0 and ej299 test")
plt.plot(RG1,exempt1,label='B0')
plt.plot(RG2,exempt2,label='EJ299')
plt.xlabel("λ(nm)")
plt.ylabel("exempt")
plt.legend()
plt.show()
fig1.savefig("spectrum1.png")
fig2.savefig("spectrum2.png")



