Python可视化应用――绘制纵向和横向条形图

哎呀,这个是最简单的,我就直接贴代码了。

import matplotlib

matplotlib.use('Agg')

import sys

import matplotlib.pyplot as plt

#set the verhical bar

def Vbar():

      plt.cla()

      rect=plt.bar(left=range(len(ave)),height=ave,align="center")

      plt.ylabel(u'Performance')

      plt.xlabel(u'Environment')

      plt.xticks(range(len(get_envnum())),get_envnum(),FontSize=6)

      plt.legend((rect,),(u'Requests per second',))

      x = np.arange(len(get_envnum()))

      for i in range(len(get_envnum())):

          z = [x[i],x[i]]

          w = [ave[i]-std[i],ave[i]+std[i]]

          plt.plot(z,w,color='red')

      for x,y in enumerate(ave):

          plt.text(x,y+100,'%s' %round(y,1),ha='center')

      plt.savefig("V.png",format='png')

#set the horizontal bar

def Hbar():

      plt.cla()

      rect=plt.barh(bottom=range(len(ave)),width=ave,align="center")

      plt.ylabel(u'Environment')

      plt.xlabel(u'Performance')

      plt.yticks(range(len(get_envnum())),get_envnum(),FontSize=6)

      plt.legend((rect,),(u"Data",))

      y = np.arange(len(get_envnum()))

      for i in range(len(get_envnum())):

          z = [y[i],y[i]]

          w = [ave[i]-std[i],ave[i]+std[i]]

          plt.plot(w,z,color='red')

      for x,y in enumerate(ave):

          plt.text(y+0.1,x,'%s' %round(y,1),va='center')

      plt.savefig("H.png",format='png')

这里我封装成了两个方法,可以注意到第一条都是plt.cla(),这是用来擦除绘图的,因为如果你先调用Vbar方法,再调用Hbar方法,就会发现,后者的图片会出错。

这个没有图了,因为不小心给删掉了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我爱Python,从自学开始。 打死不学Python的我,终于在部门的业务下哭唧唧选择屈服,毕竟胳膊拧不过大腿丫,...
    方程不等式阅读 13,646评论 0 0
  • # -*- coding: utf-8 -*- from __future__ import division f...
    小豆角lch阅读 1,474评论 0 1
  • 01: 坚挺到最后放假的工美系 害多数女生一夜间变的像怨妇那样 用洒口有气泡的言语来发泄不满,我也爽来着 但我不像...
    Akasha_阅读 136评论 0 0
  • 此刻,外面下着雨,听着雨水嘀嗒的声音很舒服,今天想写写关于值得感的事。从哪里开始写呢,深呼吸了一下,想起小的...
    心知心语阅读 774评论 3 1
  • 随着时间的流逝人一天天长大,世事纷纷接踵而来,升学、考试、就业、恋爱、结婚、生子等等等等。不知不觉就已经到了而立之...
    libeatzqi阅读 199评论 1 1