matplotlib安装及使用

linux给python3安装matplotlib很简单来条命令就行了

sudo apt-get install python3-matplotlib

等待完成就可以了,然后下面测试一下.

$ python3
>>>import matplotlib
>>>

不报错就是安装成功了,下面来试试画条线.

import matplotlib.pyplot as pl
s = [1,2,3,4,5]
a = [2,3,6,7,8]
pl.plot(s,a)
pl.show()

接下来给他加上标题和刻度大小

import matplotlib.pyplot as pl
s = [1,2,3,4,5]
a = [2,3,6,7,8]
pl.title("标题",fontsize=20)
pl.xlabel("x标题",fontsize=20)
pl.ylabel("y标题",fontsize=20)
pltick_parms(axis='both',labelsize=10)
pl.plot(s,a)
pl.show()

点状的是把plot换成scatter,s是点的大小

pl.plot(s,a)
pl.scatter(s,a,s=50)

加个属性edgecolor=’none’去掉点的外伦宽,c=”是给点指定一种颜色,淡然rgb的也是可以的,例如c=(0,0,0),但必须是元组.

pl.scatter(s,a,c='red',edgecolor='none',s=50)
import matplotlib.pyplot as pl
x_a = list(range(1,1000))
y_a = [x**2 for x in x_a]
pl.scatter(x_a,y_a,c=Y_a,cmap=pl.cm.Blues,edgecolor='none',s=50)
pl.title("biaoti",fontsize=50)
pl.show()

标签

发表评论

评论列表(19)