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里面的参数与具体可取值还需要后续在学习发现,目前尚不十分清楚