博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python | 使用matplotlib.pyplot创建条形图
阅读量:2533 次
发布时间:2019-05-11

本文共 1169 字,大约阅读时间需要 3 分钟。

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 pltx1 = [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函数显示了情节。

翻译自:

转载地址:http://tfazd.baihongyu.com/

你可能感兴趣的文章
关于jquery中prev()和next()的用法
查看>>
一、 kettle开发、上线常见问题以及防错规范步骤
查看>>
eclipse没有server选项
查看>>
CRC码计算及校验原理的最通俗诠释
查看>>
QTcpSocket的连续发送数据和连续接收数据
查看>>
使用Gitbook来编写你的Api文档
查看>>
jquery扩展 $.fn
查看>>
Markdown指南
查看>>
influxDB的安装和简单使用
查看>>
JPA框架学习
查看>>
JPA、JTA、XA相关索引
查看>>
机器分配
查看>>
php opcode缓存
查看>>
springcloud之Feign、ribbon设置超时时间和重试机制的总结
查看>>
Go 结构体
查看>>
LINQ巩固
查看>>
观看杨老师(杨旭)Asp.Net Core MVC入门教程记录
查看>>
UIDynamic(物理仿真)
查看>>
Windows下安装Redis
查看>>
迷宫实现
查看>>