Python全系列 教程
3567个小节阅读:5929.6k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
131x = [2020,2025,2030,2035]
2y = [12000,11000,30000,32000]
3plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
4#绘制条形图
5#设置柱的高度
6plt.barh(x,y,height=3)
7#xlabel的名称
8plt.ylabel('年份')
9plt.xlabel('销量')
10plt.title('四年XX销量')
11#yticks
12y_ticks = [f'{i}年' for i in x]
13plt.yticks(x,y_ticks)
【示例】对部分条形图,使用颜色区分
xxxxxxxxxx
71import matplotlib.pyplot as plt
2x=range(5)
3y=[1,-3,4,-5,6]
4v_bar=plt.bar(x,y,color='lightblue')
5for bar,height in zip(v_bar,y):
6 if height<0:
7 bar.set(color='lightgreen',linewidth='3')
实时学习反馈
1.matplotlib模块中,bar(x,y,color,width)函数来生成纵向条形图,函数来生成横向条形图。
A plot(x,y)
B plt.scatter(x,y)
C barh(x,y,color,height)
D plt.legend()
2. 使用matplotlib模块对部分条形图的柱设置颜色,下划线处需要填写的代码是___:
xxxxxxxxxx
71import matplotlib.pyplot as plt
2x=range(5)
3y=[1,-3,4,-5,6]
4v_bar=plt.bar(x,y,color='lightblue')
5for bar,height in zip(v_bar,y):
6 if height<0:
7 ________________
A bar.set(color='lightgreen',linewidth='3')
B bar.color(color='lightgreen',linewidth='3')
C bar.setcolor(color='lightgreen',linewidth='3')
答案
1=>C 2=>A