当前位置:网站首页>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()

边栏推荐
猜你喜欢

Wechat applet: (update) cloud development wechat group contacts

字节云数据库未来方向的探索与实践

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

Go zero micro Service Practice Series (VII. How to optimize such a high demand)

“微博评论”的高性能高可用计算架构

How can the local / park do a good job in industrial analysis?

二叉树的序列化 力扣 297. 二叉树的序列化与反序列化 652. 寻找重复的子树

InfluxDB时序数据库系统

软件测试 接口测试 Postman测试工具 接口测试的流程 执行接口测试 接口关联 环境变量和全局变量 内置动态参数以及自动有的动态参数

Node data collection and remote flooding transmission of label information
随机推荐
Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
Software testing interface testing JMeter 5.5 installation tutorial
Shell -- text processing command
error: C2665: “QMessageBox::critical”: 4 个重载中没有一个可以转换所有参数类型
语音信号处理(二): 发声生理、听觉生理与听觉心理
剑指 Offer 38. 字符串的排列
自己收藏的一些网址
label問題排查:打不開標注好的圖像
Ansible automatic operation and maintenance
Leetcode 1385. Distance value between two arrays
sql刷题595. 大的国家
收藏!这些提高程序员生产力的工具你用过吗?
pytest初始化和清理环境
How ZABBIX 5.0 adds esxi6.7 to monitoring
众昂矿业:萤石助力氟产业锂电建设发展
constexpr 函数
Leetcode(76)——最小覆盖子串
InfluxDB时序数据库系统
MetaQ集群安装测试
Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]