xlabel函数--Matplotlib

xlabel函数使用–Matplotlib

xlabel语法、功能与参数设置可平移至ylabel。

函数语法:
xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
函数功能:
Set the label for the x-axis.
设置X轴的标签
函数参数:
xlabel: str The label text.
               字符串格式,标签文本内容
fontdict: dict, 一个字典用来控制标签的字体样式
labelpad: float, default: None ,Spacing in points from the axes bounding box including ticks and tick labels.
                浮点数,默认值为None, x/y轴的标签离x/y轴的偏移量,以点为单位
loc(location): {‘left’, ‘center’, ‘right’}, default: rcParams[“xaxis.labellocation”] (default: ‘center’) The label position. This is a high-level alternative for passing parameters x and horizontalalignment.
                标签位置,默认在中间,对于x轴是’left’,‘center’,‘right’,对于y轴则是’bottom’, ‘center’, ‘top’

Other Parameters: **kwargsText properties 。Text properties control the appearance of the label.
    其他参数 : 设置其他文本属性,控制标签文本的展示外观
在这里插入图片描述
通过labelpad参数改变x轴标签离x轴的位置
在这里插入图片描述
在这里插入图片描述
通过loc参数改变y轴标签的位置

在这里插入图片描述

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.05, 10, 1000)
y = np.cos(x)

plt.plot(x, y,lw = 2,label = 'plot figure')

plt.legend(loc = 'lower left') #指定图例位置

plt.xlabel('x-axis',labelpad =None,loc = 'right')   #增加x轴标签
plt.ylabel('testylabel',loc = 'center',
           fontdict = {'fontsize' : 15,'fontstyle' : 'oblique',
                       'color':'red','fontfamily': 'fantasy'})  #设置标签字体字典

plt.show()

font_dict控制字体式样
在这里插入图片描述
font_dict里面的参数与具体可取值还需要后续在学习发现,目前尚不十分清楚

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值