matplotlib Python的绘图库
plot(list) 函数:将列表中的值设为 y轴的范围,x轴从0开始
show() 函数:查看绘制出的图形
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()
散点图
x_values = [1, 2, 3, 4, 5]
y_values = [1, 4, 9, 16, 25]
# plt.scatter(2, 4, s=200) # 坐标(2,4)绘制一个点 s参数是点的尺寸
plt.scatter(x_values, y_values, c='red', s=200)
# 坐标(2,4)绘制一个点 s参数是点的尺寸 c='red' 散点颜色
# 设置图标标题
plt.title('Square Numbers', fontsize=24)
plt.xlabel('Value', fontsize=14)
plt.ylabel('Square of Value', fontsize=14)
# 设置刻度标记的大小
plt.tick_params(axis='both', which='major', labelsize=14) # 参数which有三种刻度,major主刻度线,minor副刻度线,both
plt.show()
x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]
其他相同