当前位置:网站首页>Matplotlib histogram of Matplotlib visualization plt bar()
Matplotlib histogram of Matplotlib visualization plt bar()
2022-06-29 23:24:00 【Guoqingru】
matplotlib matplotlib Visual histogram plt.bar()

# Prepare the data
xiaoming_score = [80,75,65,58,75,80,90] # Xiao Ming's achievements in various subjects
xiaohong_score =[90,85,75,62,75,60,80] # Xiao Hong's grades in all subjects
subjects = [' Chinese language and literature ',' English ',' mathematics ',' Physics ',' chemical ',' biological ',' sports ']

Argument parsing :
plt.bar(x = np.arange(7), # Abscissa
height = xiaoming_score, # Columnar height
width = 0.35, # Columnar width
label = ' Xiao Ming ', # label
edgecolor = 'k', # Border color
color = 'r', # Histogram color
tick_label = subjects, # Coordinate labels for each bar graph
linewidth= 3) # Bar chart border width
plt.legend() # Show labels
plt.show()

Cluster bar chart : Drawing by controlling horizontal axis coordinates
# mapping
plt.figure(figsize = (10,7))
plt.bar(x = np.arange(7),height = xiaoming_score,width = 0.35,label = ' Xiao Ming ',edgecolor = 'white',color = 'r',tick_label = subjects)
plt.bar(x = np.arange(7)+0.35,height = xiaohong_score,width = 0.35,label = ' Xiaohong ')
# Supplementary title and label
plt.title(' Xiao Ming 、 Comparison of Xiaohong's achievements in various subjects ') # Title of figure
plt.xlabel(' subject ',fontsize = 15) # Horizontal axis label
plt.ylabel(' achievement ',fontsize = 15) # Vertical label
plt.xticks(np.arange(7)+0.17,subjects,fontsize = 12) # Bar chart horizontal axis coordinates each category label
plt.legend() # Show labels for two sets of histograms
# Note the values of each bar chart , Here is the score
for i in range(len(subjects)):
plt.text(x = i-0.1, y = xiaoming_score[i]+1,s = xiaoming_score[i] ) # s Indicates the content of the comment
for i in range(len(subjects)):
plt.text(x = i+0.3, y = xiaohong_score[i]+1,s = xiaoming_score[i] )
# Display images
plt.show()

# mapping
plt.bar(x = subjects, height = xiaoming_score, label = ' Xiao Ming ', color = 'steelblue', alpha = 0.8, width = 0.35)
plt.bar(x = subjects, height = xiaohong_score, label = ' Xiaohong ', color = 'indianred', alpha = 0.8, width = 0.35, bottom=xiaoming_score)
# Supplementary title and label
plt.title(' Xiao Ming 、 Comparison of Xiaohong's achievements in various subjects ') # Title of figure
plt.xlabel(' subject ',fontsize = 15) # Horizontal axis label
plt.ylabel(' achievement ',fontsize = 15) # Vertical label
plt.xticks(np.arange(7),subjects,fontsize = 12) # Bar chart horizontal axis coordinates each category label
plt.legend() # Show labels for two sets of histograms
# Note the values of each bar chart , Here is the score
for i in range(len(subjects)):
plt.text(x = i-0.1, y = xiaoming_score[i]-30,s = xiaoming_score[i] )
for i in range(len(subjects)):
plt.text(x = i-0.1, y = xiaohong_score[i]+30,s = xiaoming_score[i] )
plt.show()

边栏推荐
猜你喜欢

Paper writing tool: latex online website

High performance and high availability computing architecture of "microblog comments" in microblog system

Design of Distributed Message Oriented Middleware

constexpr 函数

按头安利!好看又实用的电机 SolidWorks模型素材看这里

语音信号处理(三):语音信号分析【连续的“模拟信号”--采样、量化、编码-->离散的“数字信号”】
Evolution from stand-alone to distributed database storage system

Procurement intelligence is about to break out, and the "3+2" system of Alipay helps enterprises build core competitive advantages

Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles

NRM explanation
随机推荐
Solr basic operation 4
收藏!这些提高程序员生产力的工具你用过吗?
MetaQ集群安裝測試
按头安利!好看又实用的电机 SolidWorks模型素材看这里
Software testing interface testing JMeter 5.5 installation tutorial
C pointer advanced 1-- > character pointer, array pointer, pointer and array parameter transfer, function pointer
按头安利 好看又实用的点胶机 SolidWorks模型素材看这里
Leetcode(76)——最小覆盖子串
How can the local / park do a good job in industrial analysis?
Cacti关于spine轮询的设置
什么是IGMP?IGMP与ICMP有啥区别?
error: C2665: “QMessageBox::critical”: 4 个重载中没有一个可以转换所有参数类型
STM32 basic knowledge points
Halcon实用:焊点检出设计思路
matplotlib matplotlib中plt.hist()参数解释
记一次排查线上MySQL死锁过程,不能只会curd,还要知道加锁原理
采购数智化爆发在即,支出宝“3+2“体系助力企业打造核心竞争优势
基于OpenStack的虚拟机在线迁移
海外数字身份验证服务商ADVANCE.AI入选EqualOcean《2022品牌出海服务市场研究报告》
RRDtool 画MRTG Log数据