在Python中,使用matplotlib库画图时,设置纵坐标可以通过`plt.ylabel`函数来实现。下面是一个简单的示例代码,展示了如何使用matplotlib绘制折线图并设置纵坐标标签:
import matplotlib.pyplot as plt
定义数据
x_values = [1, 2, 3, 4, 5]
y_values = [1, 4, 9, 16, 25]
绘制折线图
plt.plot(x_values, y_values)
设置纵坐标标签
plt.ylabel('纵坐标标签')
显示图形
plt.show()
在这个例子中,`plt.ylabel`函数用于设置纵坐标的标签为“纵坐标标签”。你可以根据需要更改这个标签的文本。