zoukankan      html  css  js  c++  java
  • matplotlib系列——条形图

      import matplotlib.pyplot as plt
      import numpy as np
      import matplotlib
    
      x = ["战狼2","激情8","功夫瑜伽","西游伏妖","变形金刚","摔跤吧"]
      y
    = [56.01,26.94,17.53,16.49,15.45,12.96]   # 设置图形对象 :窗口 plt.figure('Figure Object 1', # 图形对象名称 窗口左上角显示 figsize = (8, 5), # 窗口大小 dpi = 120, # 分辨率 facecolor = 'white', # 背景色 ) #绘制条形图 """ left:长条形中点横坐标 height:长条形高度 长条形宽度,默认值0.8 label:为后面设置legend准备 """ rects1=plt.bar(x, y, width=0.4,label='Jacobi',alpha=0.8,color='orange') #rects1=plt.bar(x, y, width=0.4,label='Jacobi',alpha=0.8,color='orange') #横向条形图 #刻度 plt.xticks(range(len(x)),x,rotation=90,fontproperties='SimHei',fontsize=8) #plt.yticks(range(len(x)), x, rotation=90) #条形图高度的标注 for rect in rects1: height = rect.get_height() plt.text(rect.get_x() + rect.get_width()/2, height+1, height, ha="center", va="bottom",fontsize=7) #坐标轴范围 plt.xlim(-1,len(x)+1) plt.ylim(0, max(y)*1.2) #显示图例 plt.legend() #坐标轴标注 #plt.xlabel("X轴",fontproperties='SimHei',fontsize=8) plt.ylabel("Y轴",fontproperties='SimHei',fontsize=10) #标题 plt.title('电影票房',fontproperties='SimHei',fontsize=12) plt.show()

  • 相关阅读:
    deepin/uos和局域网其他机器无法ping通
    Ubuntu18.04完全卸载vscode
    批量拉取github组织或者用户的仓库
    vmware uos挂载windows共享目录
    清空容器另类方式
    time_t 时间格式化字符串
    条件变量condition_variable
    C++多维堆数组定义
    arm64 ubuntu18.04 bionic安装bcc tools
    win10下载编译chromium
  • 原文地址:https://www.cnblogs.com/Fengqiao/p/bar.html
Copyright © 2011-2022 走看看