Python——使用matplotlib绘制柱状图

Python——使用matplotlib绘制柱状图

1、基本柱状图

首先要安装matplotlib(http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot) 可以使用pip命令直接安装
[python] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. import matplotlib.pyplot as plt  
  3.   
  4. num_list = [1.5,0.6,7.8,6]  
  5. plt.bar(range(len(num_list)), num_list)  
  6. plt.show()  

2、设置颜色

[python] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. import matplotlib.pyplot as plt  
  3.   
  4. num_list = [1.5,0.6,7.8,6]  
  5. plt.bar(range(len(num_list)), num_list,fc='r')  
  6. plt.show()  

[cpp] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. import matplotlib.pyplot as plt  
  3.   
  4. num_list = [1.5,0.6,7.8,6]  
  5. plt.bar(range(len(num_list)), num_list,color='rgb')  
  6. plt.show()  

3、设置标签

[python] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. import matplotlib.pyplot as plt  
  3.   
  4. name_list = ['Monday','Tuesday','Friday','Sunday']  
  5. num_list = [1.5,0.6,7.8,6]  
  6. plt.bar(range(len(num_list)), num_list,color='rgb',tick_label=name_list)  
  7. plt.show()  

4、堆叠柱状图

[python] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. import matplotlib.pyplot as plt  
  3.   
  4. name_list = ['Monday','Tuesday','Friday','Sunday']  
  5. num_list = [1.5,0.6,7.8,6]  
  6. num_list1 = [1,2,3,1]  
  7. plt.bar(range(len(num_list)), num_list, label='boy',fc = 'y')  
  8. plt.bar(range(len(num_list)), num_list1, bottom=num_list, label='girl',tick_label = name_list,fc = 'r')  
  9. plt.legend()  
  10. plt.show()  

5、并列柱状图

[python] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. import matplotlib.pyplot as plt  
  3.   
  4. name_list = ['Monday','Tuesday','Friday','Sunday']  
  5. num_list = [1.5,0.6,7.8,6]  
  6. num_list1 = [1,2,3,1]  
  7. x =list(range(len(num_list)))  
  8. total_width, n = 0.8, 2  
  9. width = total_width / n  
  10.   
  11. plt.bar(x, num_list, width=width, label='boy',fc = 'y')  
  12. for i in range(len(x)):  
  13.     x[i] = x[i] + width  
  14. plt.bar(x, num_list1, width=width, label='girl',tick_label = name_list,fc = 'r')  
  15. plt.legend()  
  16. plt.show()  

6、条形柱状图

[python] view plain copy
  1. # -*- coding: utf-8 -*-  
  2. import matplotlib.pyplot as plt  
  3.   
  4. name_list = ['Monday','Tuesday','Friday','Sunday']  
  5. num_list = [1.5,0.6,7.8,6]  
  6. plt.barh(range(len(num_list)), num_list,tick_label = name_list)  
  7. plt.show()  

转载于:https://www.cnblogs.com/decode1234/p/8535638.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414579.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

了解 yarn 、npm、nodejs

了解 yarn 、npm、nodejs 一、前言 针对即将上线的 jeecg-boot 做一些准备。二、了解系列 1、了解 nodejs Node.js 就是运行在服务端的 JavaScript。Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台。Node.js是一个事件驱动I/O服务端JavaScript环境,基于…

Android 语音播报,语音识别demo

该功能是基于百度智能云实现的根据文字进行语音播报。 1、首先到百度智能云创建语音应用 https://console.bce.baidu.com/ai/ 填写包名创建百度语音应用,获取AppID,API Key,Secret Key 2、导入资源文件。语音jar,assets语音库&am…

jeecg自定义datagrid查询

jeecg自定义datagrid查询 为什么要写这篇文章? 我们了解,使用 jeecg 提供的 CriteriaQuery 查询方式,确实能满足绝大数的需求,但是往往有那么个比较复杂的情况,需要我们直接去写 sql,比如多表查询呀等等等…

mailto发送邮件

mailto后面加发送邮件地址&#xff0c;可以在网页上通过链接直接打开邮件客户端发送邮件&#xff1b;只有第一个可以 1 <!DOCTYPE html>2 <html>3 <head>4 <meta charset"UTF-8">5 <title></title>6 &l…

Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7:1.3.21

第一次在Android studio 创建kotlin项目。编译报错&#xff1a; Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7:1.3.21 解决方法 // implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"implementation "org.jetbrai…

jeecg自定义按钮使用exp属性不起作用

jeecg自定义按钮使用exp属性不起作用 为什么要写这篇文章&#xff1f; 之前写过一篇类似的文章 jeecg笔记之自定义显示按钮exp属性&#xff0c;但是有些小伙伴留言参考后不起作用&#xff0c;当时我的 jeecg 版本为3.7.5&#xff0c;最终以版本不同&#xff0c;暂时搁浅了。今…

使用java修改图片DPI

修改以后可以直接用PS打开看效果 全部使用rt下的类&#xff0c;无需下载其他jar包 import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGEncodeParam; import com.sun.image.codec.jpeg.JPEGImageEncoder; import javax.imageio.ImageIO; …

Android studio 创建kotlin工程

1、安装kotlin插件 打开settings页面。安装插件 2、已安装kotlin插件即可创建kotlin项目 打开New Project。选中Includ Kotlin support即可 3、创建kotlin或者java的activity 选中语音类型kotlin或者java kotlin项目创建完成 kotlin工程demo链接&#xff1a;https://download…

改造一下jeecg中的部门树

改造一下jeecg中的部门树 假装有需求 关于 jeecg 提供的部门树&#xff0c;相信很多小伙伴都已经用过了&#xff0c;今天假装有那么一个需求 "部门树弹窗选择默认展开下级部门"&#xff0c;带着这个需求再次去探索一下吧。 一、改造之前的部门选择树流程 1.1 t:depa…

html 知识

一 html是什么&#xff1f; ,1、超文本标记语言&#xff08;Hypertext Markup Language, HTML&#xff09;是一种用于创建网页的标记语言。 2、本质上是浏览器可识别的规则&#xff0c;我们按照规则写网页&#xff0c;浏览器根据规则渲染我们的网页。对于不同的浏览器&#xff…

Android kotlin基础语法

1、继承类和实现接口 继承类是冒号连接&#xff0c;java是extends连接。实现接口是逗号连接&#xff0c;java是implements连接 class MainActivity : AppCompatActivity(),MyKotlinInterface ,MyInterface{ java&#xff1a;public class Main3Activity extends AppCompatAc…

工作245:vue的注意规范之v-if 与 v-for 一起使用

当 v-if 与 v-for 一起使用时&#xff0c;v-for 具有比 v-if 更高的优先级&#xff0c;这意味着 v-if 将分别重复运行于每个 v-for 循环中 所以&#xff0c;不推荐v-if和v-for同时使用 使用推荐方式&#xff1a; 或者&#xff1a;放在计算属性遍历 当它们处于同一节点&#x…

Django create_user with is_active=False

Django create_user with is_activeFalse 下面的内容来自官方文档is_active布尔值。指示用户的账号是否激活。我们建议把这个标记设置为False 来代替删除账号&#xff1b;这样的话&#xff0c;如果你的应用和User 之间有外键关联&#xff0c;外键就不会失效。 它不是用来控制用…

Android kotlin实现底部导航栏

1、实现效果&#xff0c;可点击或者滑动切换fragment 点击 滑动 实现方法&#xff1a; 1、创建三个fragment.kt 2、创建fragmentAdapter class MyFragmentAdapter(fragmentManage…

jeecg富文本编辑器增加字体(仿宋)

jeecg富文本编辑器增加字体(仿宋) jeecg富文本编辑器增加字体(仿宋) 温馨提示&#xff1a;jeecg 提供了 uedit 富文本的实现&#xff0c;如下针对的是 uedit 增加仿宋字体示例。 主要修改三个文件&#xff1a;plug-in\ueditor\ueditor.config.js、plug-in\ueditor\lang\en\en.…

Android kotlin使用RecyclerView实例

1、创建entity类 class InternentBarEntity {var bname: String? nullvar barea: String? nullvar badddata: String? nullvar bimage: String? nullvar bid: String? null } 2、创建adapter类 /***作者&#xff1a;created by meixi*邮箱&#xff1a;15913707499…