matplotlib.pyplot.ylabel()函数
matplotlib.pyplot.ylabel()
这个函数为图形的y轴设置标签。
语法:matplotlib.pyplot.ylabel(ylabel, fontdict=None,labelpad=None)
参数:
ylabel:标签的名称
fontdict:为标签添加字体样式
labelpad:这有助于我们设置标签和轴之间的间距
示例1
import matplotlib.pyplot as plt
# setting x values
x =['Geeks', 'for', 'geeks', 'tutorials']
# Setting y values
y =[1, 2, 3, 4]
# Adding label on the y-axis
plt.ylabel('Numbers label')
# plotting the graph
plt.plot(x, y)
输出:
示例2
import matplotlib.pyplot as plt
x =['Geeks', 'for', 'geeks', 'tutorials']
y =[1, 2, 3, 4]
# Adding space between label and
# axis by setting labelpad
plt.ylabel('Numbers label', labelpad = 50)
plt.plot(x, y)
输出:
示例# 3:
import matplotlib.pyplot as plt
x =['Geeks', 'for', 'geeks', 'tutorials']
y =[1, 2, 3, 4]
# Setting font dictionary
font = {'family': 'Verdana',
'color': 'green',
'size': 20,
}
# Adding the font styles to the label
plt.ylabel('Numbers label', fontdict = font)
plt.plot(x, y)
Output: