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.pswp.cn/news/380091.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/380091.shtml
英文地址,請注明出處:http://en.pswp.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 代表存入數據庫時…