Python如何在画布中绘制多个图表?
python如何在画布中绘制多个图表?
1、说明
在绘制图表时,Matplotlib模块默认先创建一块画布,然后将绘制的图表显示在画布上。
若要在一个画布上画多个图表,可以使用subplot()函数将画布分成若干区域,然后在每个区域上分别画不同的图表。
subplot()函数的参数为3个整数:
第一个数字表示将整个画布分成若干行;
第二个数字表示将整个画布分成若干列;
第三个数字表示在第几个区域中绘制图表,区域编号规则是,按从左到右,从上到下的顺序,从1开始编号。
2、实例
importmatplotlib.pyplotasplt
#如果值中有中文字符,则必须在绘制图表前加上这两行代码
plt.rcParams['font.sans-serif']=['MicrosoftYaHei']
plt.rcParams['axes.unicode_minus']=False
x=['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
y=[50,45,65,76,75,85,55,78,86,89,94,90]
plt.subplot(2,2,1)
plt.pie(y,labels=x,labeldistance=1.1,startangle=90,counterclock=False)
plt.subplot(2,2,2)
#参数width用于设置柱子的宽度,默认值为0.8。如果设置为1,则各个柱子会紧密相连;如果设置为大于1的数,则各个柱子会相互交叠
plt.bar(x,y,width=0.5,color='r')
plt.subplot(2,2,3)
#参数color用于设置柱子的填充颜色,具体取值见后面的说明
plt.stackplot(x,y,color='r')
plt.subplot(2,2,4)
plt.plot(x,y,color='r',linestyle='solid',linewidth=2,marker='o',markersize=10)
plt.show()
以上就是Python在画布中绘制多个图表的方法,希望能对大家有所帮助!更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
Python如何在画布中绘制多个图表?
python如何在画布中绘制多个图表?1、说明在绘制图表时,Matplotlib模块默认先创建一块画布,然后将绘制的图表显示在画布上。若要在一个画布上画...详情>>
2023-11-14 21:04:27
python@是什么意思
python中@是什么意思通常我们所见的@符号是用于邮箱中,而在python中@符号也有着重要的作用,一个是表示修饰符,另一个则是表示矩阵乘法。表示...详情>>
2023-11-14 20:07:01
python进程池的使用注意
python进程池的使用注意1、使用注意(1)使用池时,如果未指定进程数,则默认为CPU核心数。(2)核心数量对应于计算机的逻辑处理器数量(任务管理器-...详情>>
2023-11-14 18:42:08
python多线程中join的应用场景
python多线程中join的应用场景1、线程的join()方法表示等这个线程运行完毕,程序再往下运行。我们来看下面的例子fromthreadingimportThreadt=ti...详情>>
2023-11-14 18:16:56热门推荐
python中scipy.linalg.inv()功能是什么?
沸requests在python中如何发送请求
热python自定义模块的注意点
热python如何将相对路径转换为绝对路径?
新python在列表中和列表末尾添加元素的方法
Python如何在画布中绘制多个图表?
pythonQueue在python的实例化
python@是什么意思
pythonconftest如何使用?
python列表运算详解
python进程池的使用注意
python多线程中join的应用场景
python异步中loop抛出异常的解决
pythontime模块处理系统时间的函数
技术干货






