赞
踩
1.柱状图
import matplotlib.pyplot as plt
import numpy as np
#中文字体
font={'family':'SimHei','size':'20'}
plt.rc('font',**font)
plt.rcParams['axes.unicode_minus']=False
x=[1,2,3,4,5,6,7,8]
y=[3,1,4,5,7,8,6,4]
plt.bar(x,y)
plt.show()
2.直方图
import matplotlib.pyplot as plt
import numpy as np
x=np.random.randint(0,10,100)
print(x)
plt.hist(x)
plt.show()
3.饼图
import matplotlib.pyplot as plt
import numpy as np
x=[1,2,3,4,5,6,7,8]
print(x)
plt.pie(x)
plt.show()
4.雷达图
import matplotlib.pyplot as plt
import numpy as np
bar_slices=20
theta=np.linspace(0.0,2*np.pi,bar_slices,endpoint=False)
r=30*np.random.rand(bar_slices)
plt.polar(theta,r,color='chartreuse',linewidth=2,marker='*',mfc='b',ms=10)
plt.show()
5.散点图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
a=np.random.randn(10)
b=np.random.randn(10)
#s表示散点标记的大小,这个是可选项 c表示散点标记的颜色,可选项 cmap表示将浮点数映射成颜色的颜色映射表
plt.scatter(a,b,s=np.power(10*a+20*b,2),c=np.random.rand(10),cmap=mpl.cm.Greens,marker='*')
plt.show()
6.棉棒图
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
x=np.linspace(0.5,2*np.pi,20)
y=np.random.randn(20)
#linefmt:棉棒的样式。 markerfmt:棉棒末端的样式。 basefmt:指定基线的样式。
plt.stem(x,y,linefmt='--',markerfmt='o',basefmt='-')
plt.show()
7.箱线图
import matplotlib.pyplot as plt
import numpy as np
x=np.random.randn(10)
plt.boxplot(x)
plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。