Python | 使用matplotlib.pyplot创建条形图

Problem statement: Using matplotlib.pyplot library in python draw a bar graph with two values for comparison, using different colors.

问题陈述:在python中使用matplotlib.pyplot库使用不同的颜色绘制带有两个值的条形图以进行比较。

Program:

程序:

import matplotlib.pyplot as plt
x1 = [2,4,6,8,10]
y1=[3,9,11,2,6]
x2=[1,3,5,7,9]
y2=[6,4,7,8,3]
plt.bar(x1,y1,label ='Bars1', color='g')
plt.bar(x2,y2,label = 'Bars2', color='r')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Bar Graph2')
plt.legend()
plt.show()

Output

输出量

bar graph program output in Python

Explanation:

说明:

Python library matplotlib.pyplot is used to draw the above chart. Four random variables x1 y1 and x2 y2 are taken with random values. The bar function plots a bar plot. The second bar function used draws another bar plot in the same frame. The bar function takes 2 arguments i.e. x and y and a label variable gives the label to the plot. To give the title to the plot the title function is used. To show the legend the legend function is used and finally to show the plot the show function.

Python库matplotlib.pyplot用于绘制以上图表。 四个随机变量x1 y1和x2 y2带有随机值。 条形函数绘制条形图。 使用的第二个条形图函数在同一帧中绘制另一个条形图。 bar函数采用2个参数,即x和y,以及一个label变量为该图提供标签。 为了给绘图赋予标题,使用了标题功能。 为了显示图例,使用了图例功能,最后使用show函数显示了情节。

翻译自: https://www.includehelp.com/python/create-a-bar-graph-with-using-matplotlib-pyplot.aspx

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

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

相关文章

SQLSERVER内核架构剖析

我们做管理软件的,主要核心就在数据存储管理上。所以数据库设计是我们的重中之重。为了让我们的管理软件能够稳定、可扩展、性能优秀、可跟踪排错、可升级部署、可插件运行,我们往往研发自己的管理软件开发平台。我们总是希望去学习别人的开发平台&#…

输出以下的杨辉三角形(要求输入个数字,表示需要输出几行)

#include<stdio.h> int main() {int i,j,k,n,x,a[100][100];a[0][1]1;scanf("%d",&x);for(i1;i<x;i){for(j1;j<i;j){a[i][j]a[i-1][j-1]a[i-1][j];printf("%5d ",a[i][j]);//%5d 表示右对齐隔5个空格&#xff1b;}//同理&#xff0c;%-5d…

远控免杀专题(22)-SpookFlare免杀

转载&#xff1a;https://mp.weixin.qq.com/s/LfuQ2XuD7YHUWJqMRUmNVA 免杀能力一览表 几点说明&#xff1a; 1、上表中标识 √ 说明相应杀毒软件未检测出病毒&#xff0c;也就是代表了Bypass。 2、为了更好的对比效果&#xff0c;大部分测试payload均使用msf的windows/mete…

二维动态数组定义及二维静态数组与**P的区别

矩力集成2008年校园招聘笔试题&#xff1a;动态申请一个二维数组存储图像阵列 传统的解决方案是分配一个指针数组, 然后把每个指针初始化为动态分配的 列"。 以下为一个二维的例子: //typedef int (*arraypoiter)[ncolumns]; int **dynamic_alloc_arrays(unsigned int nro…

置换元素和非置换元素_循环置换数组元素的C程序

置换元素和非置换元素Problem statement: Write a c program to cyclically permute the element of an array. (In right to left direction). Array should be taken as input from the user. 问题陈述&#xff1a;编写一个c程序来循环置换array的元素 。 (从右到左方向)。 数…

最新Asp.net源码推荐列表(4月7日)

好久没有在cnblogs给大家发布asp.net源码了&#xff0c;把最近整理的一些发给大家&#xff0c;希望对大家有所帮助&#xff0c;以后争取保持每周发布&#xff01;- WOBIZ第一季1.2版源码 Hits:29 2008-4-7 [结构图] [^][VS2005Access] 电子商务2.0软件是窝窝团队基于对互联网…

远控免杀专题(23)-SharpShooter免杀

转载&#xff1a;https://mp.weixin.qq.com/s/EyvGfWXLbxkHe7liaNFhGg 免杀能力一览表 几点说明&#xff1a; 1、上表中标识 √ 说明相应杀毒软件未检测出病毒&#xff0c;也就是代表了Bypass。 2、为了更好的对比效果&#xff0c;大部分测试payload均使用msf的windows/mete…

MySQL 发展史

一.MySQL 标志说明MySQL的海豚标志的名字叫“sakila”&#xff0c;它是由MySQL AB的创始人从用户在“海豚命名”的竞赛中建议的大量的名字表中选出的。获胜的名字是由来自非洲斯威士兰的开源软件开发者Ambrose Twebaze提供。根据Ambrose所说&#xff0c;Sakila来自一种叫SiSwat…

scanf读取字符_在C语言中使用scanf()读取整数时跳过字符

scanf读取字符Let suppose, we want to read time in HH:MM:SS format and store in the variables hours, minutes and seconds, in that case we need to skip columns (:) from the input values. 假设&#xff0c;我们要读取HH&#xff1a;MM&#xff1a;SS格式的时间 &…

An Algorithm Summary of Programming Collective Intelligence (3)

k-Nearest Neighbors kNN(不要问我叫什么)PCI里面用kNN做了一个价格预测模型&#xff0c;还有一个简单的电影喜好预测。简单来说就是要对一个东西做数值预测&#xff0c;就要先有一堆已经有数值的东西&#xff0c;从里面找出和要预测的东西相似的&#xff0c;再通过计算这些相似…

远控免杀专题(24)-CACTUSTORCH免杀

转载&#xff1a;https://mp.weixin.qq.com/s/g0CYvFMsrV7bHIfTnSUJBw 免杀能力一览表 几点说明&#xff1a; 1、上表中标识 √ 说明相应杀毒软件未检测出病毒&#xff0c;也就是代表了Bypass。 2、为了更好的对比效果&#xff0c;大部分测试payload均使用msf的windows/mete…

DOM快捷键

DOM所有的命令(CMD) 步骤/方法 cmd命令大全&#xff08;第一部分&#xff09;winver---------检查Windows版本 wmimgmt.msc----打开windows管理体系结构(WMI) wupdmgr--------windows更新程序 wscript--------windows脚本宿主设置 write----------写字板 winmsd---------系统…

病毒的手工排除与分析(更新完毕)

作者简介杨京涛    8年以上的IT行业经验&#xff0c;理解企业需求&#xff0c;有企业ERP软件部署规划能力&#xff0c;有综合布线网络规划和管理能力。熟悉软件以及各类硬件&#xff0c;电话程控设备&#xff0c;各类网络设备的管理维护。有编程基础,熟悉VBA、脚本、批处理…

JavaScript中的String substring()方法和示例

JavaScript | 字符串substring()方法 (JavaScript | String substring() Method) The String.substring() method in JavaScript is used to return a part of the string. The substring() extracted is from the given start and end index of the string. JavaScript中的Str…

Java——方法(练习九九乘法表)

public static void(int,byte…) xxx(int a,int b) 修饰符 返回值类型 方法名(参数类型 参数名1&#xff0c;参数类型 参数名2…)&#xff5b; 方法体语句&#xff1b; return 返回值&#xff1b; &#xff5d; public class fangfa {public static void main(String[] ar…

UVA 10405-Longest Common Subsequence

最长公共子序列&#xff0c;值得注意的是这道题不能用scanf读字符串。 #include<stdio.h>#include<string.h>#define MAXD 1005char s1[MAXD], s2[MAXD];int dp[MAXD][MAXD];int max( int a, int b){return a > b ? a : b;}void solve(){int len1 strlen(s1 …

对初学者的几点建议

http://www.cnblogs.com/thcjp/archive/2007/06/14/783157.html 天轰穿vs2005入门.net2.0系列视频教程推出已经有接近8个月了&#xff0c;这期间我收到非常多的反馈&#xff0c;我只能用非常来形容&#xff0c;呵呵&#xff0c;当然也了解了很多人的心理和学习方法。但是很遗憾…

系统固件升级_固件和操作系统之间的差异

系统固件升级固件 (Firmware) Firmware is somewhere similar to software but it is not a software. Somehow it is a modified form of software. 固件与软件相似&#xff0c;但不是软件。 不知何故&#xff0c;它是软件的修改形式。 Firmware is fixed data or code that …

cobalt strick 4.0 系列教程 (5)--- 获取立足点

https://blog.ateam.qianxin.com/CobaltStrike4.0%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C_%E4%B8%AD%E6%96%87%E7%BF%BB%E8%AF%91.pdf 0x01 客户端 System Profiler [即探针] System Profiler 是一个为客户端攻击提供的侦察工具。这个工具启动一个本地的 web 服务器&#xff0…

[转]sql,N/$/#/@的含义和作用

declare sql nvarchar(4000)set sql Nselect TotalRecordscount(*) from N( sqlFullPopulate N) a EXEC sp_executesql sql,NTotalRecords int output, TotalRecords output 问题&#xff1a;sql 后面有个N, N 起什么作用? 答案&#xff1a; 加上 N 代表存入数据库时…