少量数据的散点图
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import matplotlib.pyplot as plt x_value = [1, 2, 3, 4, 5] y_value = [1, 4, 9, 16, 25] plt.scatter(x_value, y_value, s=200) # 设置标题, 以及给坐标轴加上标签 plt.title("Square Numbers", fontsize=14) plt.xlabel("Value", fontsize=14) plt.ylabel("Square of Value", fontsize=14) # 设置刻度标记大小 plt.tick_params(axis="both", which="major", labelsize=14) # 显示 plt.show()大量数据的散点图
#!/usr/bin/env python3 # -*- coding:utf-8 -*- import matplotlib.pyplot as plt x_value = [i for i in range(1000)] y_value = [i * i for i in x_value] # edgecolors="none" 删除数据点的轮廓 # c: 设置颜色 plt.scatter(x_value, y_value, c='red', edgecolors="none", s=20) # 设置标题, 以及给坐标轴加上标签 plt.title("Square Numbers", fontsize=14) plt.xlabel("Value", fontsize=14) plt.ylabel("Square of Value", fontsize=14) # 设置每个坐标轴的取值范围 plt.axis([0, 1100, 0, 1100000]) # 保存图表 # bbox_inches="tight" : 裁剪掉多余的空白区域 plt.savefig("scatter_plot.png", bbox_inches="tight") # 显示 plt.show()