matplotlib库使用

axes

Axes.barh

创建一个水平条形图。

The bars are positioned at y with the given alignment. Their dimensions are given by width and height. The horizontal baseline is left (default 0).

Many parameters can take either a single value applying to all bars or a sequence of values, one for each bar.

参数:

  • y:float or array-like,bars的y坐标。
  • width:float or array-like,bars的宽度
  • height:float or array-like, default: 0.8,bars的高度
  • left:float or array-like, default: 0,The x coordinates of the left sides of the bars.
  • align:{‘center’, ‘edge’}, default: ‘center’,Alignment of the base to the y coordinates*:
    ‘center’: Center the bars on the y positions.
    ‘edge’: Align the bottom edges of the bars with the y positions.
    To align the bars on the top edge pass a negative height and align=‘edge’.

返回值:

  • BarContainer:Container with all the bars and optionally errorbars.

其他参数:

在这里插入图片描述

pyplot

rcdefaults
subplots

matplotlib.pyplot.subplots

函数原型:

matplotlib.pyplot.subplots(
	nrows=1, 
	ncols=1, 
	*, 
	sharex=False, 
	sharey=False, 
	squeeze=True, 
	subplot_kw=None, 
	gridspec_kw=None, 
	**fig_kw
)

函数创建一个figure以及一组subplots。

参数:

  • nrows, ncols:(int类型,默认为1),指代subplot网格中的行数和列数
  • 待补充
  • **fig_kw:所有额外的关键字参数都会被传递给pyplot.figure调用

返回值:

  • fig:(figure)
  • ax:(axes.Axes)或者Axes数组:ax可以是单个的Axes对象,当创建多于一个subplot时ax就是Axes数组。The dimensions of the resulting array can be controlled with the squeeze keyword, see above.

常用的处理返回值的方式如下:

# 使用ax存储单个Axes
fig,ax=plt.subplots()

# 使用ax存储多个Axes
fig,axs=plt.subplots(2,2)

# 使用元组unpacking多个Axes
fig, (ax1, ax2) = plt.subplots(1, 2)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)

https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值