mpl_squares

import matplotlib.pyplot as plt

# 绘制简单折线图

"""first_version"""
squares = [1,4,9,16,25]
plt.plot(squares)   # plot 接受一个列表,将其当作y值并自动匹配x值绘出曲线图


"""second_version"""
squares = [value**2 for value in range(1,6)]
plt.plot(squares,linewidth=5)   # linewidth 参数决定了plot绘制线条的粗细

# 设置图表标题,并给坐标轴加上标签
plt.title("Square Numbers",fontsize=14)  # title方法指定标题   ,fontsize设置图表文字大小
plt.xlabel("Value",fontsize=14)
plt.ylabel("Square of Value",fontsize=14)

# 设置刻度标记的大小
plt.tick_params(axis="both",labelsize=14)  # tick_params 设置刻度的样式,labelsize 设置刻度字号


"""third_version -- 校正图形"""
# 前面plot自动匹配的x坐标出错,现在同时提供给plot输入和输出值
# plot默认第一个数据点对应 x=0 
input_value = [value for value in range(1,6)]
squares = [value**2 for value in range(1,6)]
plt.plot(input_value,squares,linewidth=5)


plt.show()

猜你喜欢

转载自blog.csdn.net/wyzworld/article/details/88244956