您的位置:首页 > 编程语言 > Python开发

Python学习笔记(8)数据可视化

2019-05-08 19:00 417 查看
[code]#encoding=gbk

import matplotlib.pyplot as plt

#1.使用plot绘制折线图
values = [1,2,3,4,5]
squares = [1,4,9,16,25]
#plt.plot(squares)
plt.plot(values,squares,linewidth=5)
#设置图标标题,并给坐标轴加上标签
plt.title('Squares Numbers', fontsize=24)
plt.xlabel('Value', fontsize=14)
plt.ylabel('Squares of Value', fontsize=14)
plt.tick_params(axis='both',labelsize=14) #设置刻度标记的大小
plt.show()

#2.使用scatter()绘制散点图
#plt.scatter(2,4,s=200)   #s制定点的尺寸
plt.scatter(values,squares,s=200)
plt.title('Squares Numbers', fontsize=24)
plt.xlabel('Value', fontsize=14)
plt.ylabel('Squares of value', fontsize=14)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.show()

x_values = list(range(1,1001))
y_values = [x ** 2 for x in x_values]
#plt.scatter(x_values, y_values, c='red', s=10)       #参数c设置点的颜色,也可c=(0,0.5,0.8) RGB颜色
plt.scatter(x_values, y_values, c=y_values, cmap=plt.cm.Blues, edgecolor='none', s=10)  #使用颜色映射
plt.title('Squares Numbers', fontsize=24)
plt.xlabel('Values',fontsize=14)
plt.ylabel('Square of Value', fontsize=14)
plt.tick_params(axis='both',which='major',labelsize=14)
#plt.show()
#自动保存图表,第一个参数是保存的位置,第二个参数是剪裁多余的空白区域,supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz
plt.savefig('C:\\Users\\bingk\\Desktop\\python_dir\\picture\\Square_numbers.png',bbox_inches='tight')

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: