Python数据可视化之画图安装数据可视化模块matplotlib:pip install matplotlib
导⼊matplotlib模块下的pyplot
1 折线图
from matplotlib import pyplot
#横坐标
year=[2010,2012,2014,2016]
#纵坐标
perple=[20,40,60,100]
#⽣成折线图:函数polt
pyplot.plot(year,perple)
#设置横坐标说明
pyplot.xlabel('year')
#设置纵坐标说明
pyplot.ylabel('population')
#添加标题
pyplot.title('Population year correspondence')
#设置纵坐标刻度
# 显⽰⽹格
显⽰图表
pyplot.show()
2 散点图
⽤两种⽅法
第⼀种:只需将函数polt换成scatter即可.
from matplotlib import pyplot
#横坐标
year=[2010,2012,2014,2016]
#纵坐标
perple=[20,40,60,100]
#⽣成散点图:函数scatter
pyplot.scatter(year,perple)
#设置横坐标说明
pyplot.xlabel('year')
#设置纵坐标说明
pyplot.ylabel('population')
#添加标题
pyplot.title('Population year correspondence')
#设置纵坐标刻度
# 显⽰⽹格
显⽰图表
pyplot.show()
第⼆种⽅法:在polt函数⾥添加第三个参数 “o”.
可以更改点的颜⾊和类型,如红⾊,五⾓型:把plot第三个参数改为'rp'.
#点的颜⾊
c–cyan–青⾊
r–red–红⾊
m–magente–品红
g–green–绿⾊
b–blue–蓝⾊
y–yellow–黄⾊
k–black–⿊⾊
w–white–⽩⾊
#线的类型
– 虚线
-. 形式即为-.
: 细⼩的虚线
#点的类型
s–⽅形
h–六⾓形
H–六⾓形
*–*形
±-加号
x–x形
d–菱形
D–菱形
p–五⾓形
from matplotlib import pyplot
#横坐标
year=[2010,2012,2014,2016]
#纵坐标
perple=[20,40,60,100]
#⽣成散点图:函数polt
pyplot.plot(year,perple,'rp')
#设置横坐标说明python新手代码画图
pyplot.xlabel('year')
#设置纵坐标说明
pyplot.ylabel('population')
#添加标题
pyplot.title('Population year correspondence')
#设置纵坐标刻度
# 显⽰⽹格
显⽰图表
pyplot.show()
总结
以上就是这篇⽂章的全部内容了,希望本⽂的内容对⼤家的学习或者⼯作具有⼀定的参考学习价值,谢谢⼤家对的⽀持。如果你想了解更多相关内容请查看下⾯相关链接

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。