【Python】可视化---axhline()函数

一、函数功能:绘制平行于x轴的水平参考线

二、语法:plt.axhline(y=0.0, c=“r”, ls=“–”, lw=2)

三、参数解读:

y:水平参考线的出发点

c:参考线的线条颜色

ls:参考线的线条风格

lw:参考线的线条宽度

平移性:上面的函数,同样适用于axvline()函数

四、举例说明

(1)不加参考线

from cProfile import label
from matplotlib.lines import lineStyles
from numpy import cumsum
import torch
from torch.distributions import multinomial
from d2l import torch as d2l
fair_probs=torch.ones([6])/6
counts=multinomial.Multinomial(10,fair_probs).sample((500,))
cum_counts=counts.cumsum(dim=0)
estimators=cum_counts/cum_counts.sum(dim=1,keepdim=True)
d2l.set_figsize((12,8))
for i in range(6):
    d2l.plt.plot(estimators[:,i].numpy(),label=("P(die="+str(i+1)+")"))
# d2l.plt.axhline(y=0.175,color='black',linestyle='dashed')
d2l.plt.gca().set_xlabel('Group of experiments')
d2l.plt.gca().set_ylabel('Estimators probability')
d2l.plt.legend()
d2l.plt.show()

在这里插入图片描述

(2)选择加参考线

from cProfile import label
from matplotlib.lines import lineStyles
from numpy import cumsum
import torch
from torch.distributions import multinomial
from d2l import torch as d2l
fair_probs=torch.ones([6])/6
counts=multinomial.Multinomial(10,fair_probs).sample((500,))
cum_counts=counts.cumsum(dim=0)
estimators=cum_counts/cum_counts.sum(dim=1,keepdim=True)
d2l.set_figsize((12,8))
for i in range(6):
    d2l.plt.plot(estimators[:,i].numpy(),label=("P(die="+str(i+1)+")"))
d2l.plt.axhline(y=0.175,color='black',linestyle='dashed')
d2l.plt.gca().set_xlabel('Group of experiments')
d2l.plt.gca().set_ylabel('Estimators probability')
d2l.plt.legend()
d2l.plt.show()

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旅途中的宽~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值