Python中plot()画图添加数据标签,显示点对应的数值

创建子图的好处:

  1. 每个子图可以单独操作,想画啥就画啥
  2. 各个子图之间可以共享坐标轴,便于同一量纲去比较数值的大小
fig,((ax1,ax2,ax3,ax4,ax5,ax6)) = plt.subplots(1,6,figsize=(22,4),sharex=True,sharey=True)
##设定子图间距 , left < right, top > bottom, 数字表示窗口大小的比例(如下则子图间距为窗口大小的1%) 
plt.subplots_adjust(left=0, top= 0.96, right = 0.96, bottom = 0.04, wspace = 0.05, hspace = 0.1)

x1 = np.array(result.loc[result['dict_value']=='渠道1']['clue_time'])
y1 = np.array(result.loc[result['dict_value']=='渠道1']['only_mobiles'])
ax1.plot(x1,y1,'o-')

for x,y in zip(x1,y1):
    ax1.text(x,y,'%.0f' % y,fontdict={'fontsize':14})
    
ax1.set_title("渠道1",fontdict={'fontsize':16})

plt.text()可以实现在画图中增加数据标签:

  • x,y 是一组标量,可为数组对象,不可为Serise对象
  • x,y 提供了需要展示的文本对应的位置,即通过x,y坐标轴定位
  • s参数:是一个string对象,是需要展示在图上的内容

Signature: ax2.text(x, y, s, fontdict=None, withdash=, **kwargs)
Docstring:
Add text to the axes.
Add the text s to the axes at location x, y in data coordinates.
Parameters
x, y : scalars
The position to place the text. By default, this is in data
coordinates. The coordinate system can be changed using the
transform parameter.
s : str
The text.
fontdict : dictionary, optional, default: None
A dictionary to override the default text properties. If fontdict
is None, the defaults are determined by your rc parameters.
withdash : boolean, optional, default: False
Creates a ~matplotlib.text.TextWithDash instance instead of a
~matplotlib.text.Text instance.
Returns
text : .Text
The created .Text instance.
Other Parameter
**kwargs : ~matplotlib.text.Text properties.
Other miscellaneous text parameters.
Examples
Individual keyword arguments can be used to override any given
parameter::

text(x, y, s, fontsize=12)
The default transform specifies that text is in data coords,
alternatively, you can specify text in axis coords ((0, 0) is
lower-left and (1, 1) is upper-right). The example below places
text in the center of the axes::
text(0.5, 0.5, ‘matplotlib’, horizontalalignment=‘center’,
… verticalalignment=‘center’, transform=ax.transAxes)
You can put a rectangular box around the text instance (e.g., to
set a background color) by using the keyword bbox. bbox is
a dictionary of ~matplotlib.patches.Rectangle
properties. For example::
text(x, y, s, bbox=dict(facecolor=‘red’, alpha=0.5))
File: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/axes/_axes.py
Type: method

在这里插入图片描述

👏👏👏再看看我们以前的文章😃😃😃
🌺 Excel中数据分析工具库-相关系数篇
🌺 干货,手把手教会你做相关性分析
🌺 5年数据分析路,小结。
🌺 用户细分及画像分析
🌺 K-近邻算法及实践

欢迎关注,微信公众号“数据分析师之家
扫描二维码 关注我们
💁提供职业规划、简历指导、面试辅导服务哦
QQ交流群:753936858(原群已满,新群号)
在这里插入图片描述

数据分析之家联合JEE RAY品牌为粉丝派发福利

在这里插入图片描述
添加粉丝福利派发官,领取粉丝福利哦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值