Python | Pyplot标签

There are the following types of labels,

标签有以下几种,

1)X轴贴标 (1) X-axis labelling)

plt.xlabel('Number Line')
# Default labelling

Python | Pyplot Labelling (1)
plt.xlabel('Number Line', color='green')
#Font colour Changed

Python | Pyplot Labelling (2)
plt.xlabel('Number Line', color='Green', fontsize=15)
#Font size Change

Python | Pyplot Labelling (3)
plt.xlabel('Number Line', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))
#Background Box Addition with opaque ratio

Python | Pyplot Labelling (4)

2)Y轴贴标 (2) Y-axis labelling)

plt.ylabel('Function')
#Default Labelling

Python | Pyplot Labelling (5)
plt.xlabel('Function', color='green')
#Colour Change

Python | Pyplot Labelling (6)
plt.xlabel('Function', color='Green', fontsize=15)
#Font Size Modification

Python | Pyplot Labelling (7)
plt.xlabel('Function', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))
#Background Box Addition with opaque ratio

Python | Pyplot Labelling (8)

pythion代码演示pyplot标签示例 (Pythion code to demonstrate example of pyplot labelling)

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(500)
y1 = np.arange(500)
for i in range(500):
    y1[i] = 2*x[i] + np.random.randint(0,56)

#x-axis labelling
#default 
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line')

#Colour
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line', color='green')

#size 
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line', color='Green', fontsize=15)

#Background Box
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))

#y-axis labelling
#default 
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function')

#Colour
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function', color='g')

#size 
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function', color='Green', fontsize=15)

#Background Box
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))

Output:

输出:

Output is as figure


翻译自: https://www.includehelp.com/python/pyplot-labelling.aspx

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值