1 importmatplotlib.pyplot as plt2
3 #x_values = [1, 2, 3, 4, 5]
4 #y_values = [1, 4, 9, 16, 25]
5 #plt.scatter(x_values, y_values, s=100)
6 ##设置图表标题并给坐标轴加上标签
7 #plt.title("Squares of Number", fontsize=24)
8 #plt.xlabel("Value", fontsize=14)
9 #plt.ylabel("Square of Value", fontsize=14)
10 ##设置刻度标记的大小
11 #plt.tick_params(axis='both', which='major', labelsize=14)
12 #13 #plt.show()
14
15 x_values = list(range(1, 1001))16 y_values = [x**2 for x inx_values]17 #去黑色轮廓
18 #plt.scatter(x_values, y_values, c='red',edgecolors='none', s=40)
19 plt.scatter(x_values, y_values, c=y_values, cmap=plt.cm.Blues,20 edgecolors='none', s=40)21 #设置图表标题并给坐标轴加上标签
22 plt.title("Squares of Number", fontsize=24)23 plt.xlabel("Value", fontsize=14)24 plt.ylabel("Square of Value", fontsize=14)25 #设置刻度标记的大小
26 plt.tick_params(axis='both', which='major', labelsize=14)27 #设置坐标轴的取值范围
28 plt.axis([0, 1100, 1, 1100000])29
30 plt.show()31 #plt.save('squares_plot.png'(文件名), bbox_inches='tight'(将图表多余的空白部分剪掉))
32 #用它替换plt.show实现自动保存图表