import matplotlib.pyplot as plt
import numpy as np
x = np.array([1,2,3,4,5])
y = x + 3
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x111dc3f28>]
plt.plot(x,y)
plt.plot(x+1,y-2)
[<matplotlib.lines.Line2D at 0x111e38b00>]
plt.plot(x,y,x+1,y-2)
[<matplotlib.lines.Line2D at 0x111f80a20>,
<matplotlib.lines.Line2D at 0x111f80be0>]
plt.figure(figsize=(5,9)) # 放置在绘图的plot方法之前
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x1120aebe0>]
plt.plot(x,y,label='x,y')
plt.plot(x+1,y-2,label='x+1,y-2')
plt.legend() # 图例生效
<matplotlib.legend.Legend at 0x11693a5f8>
plt.plot(x,y)
plt.xlabel('temp')
plt.ylabel('dist')
plt.title('dist&temp')
Text(0.5,1,'dist&temp')
fig = plt.figure() # 该对象的创建一定要放置在plot绘图之前
plt.plot(x,y,label='x,y')
fig.savefig('./123.png')
plt.plot(x,y,c='red',alpha=0.5)
[<matplotlib.lines.Line2D at 0x1170d2ef0>]
plt.bar(x,y)
<BarContainer object of 5 artists>
data = [1,1,2,2,2,3,4,5,6,6,6,6,6,6,7,8,9,0]
plt.hist(data,bins=20)
(array([1., 0., 2., 0., 3., 0., 1., 0., 1., 0., 0., 1., 0., 6., 0., 1., 0.,
1., 0., 1.]),
array([0. , 0.45, 0.9 , 1.35, 1.8 , 2.25, 2.7 , 3.15, 3.6 , 4.05, 4.5 ,
4.95, 5.4 , 5.85, 6.3 , 6.75, 7.2 , 7.65, 8.1 , 8.55, 9. ]),
<a list of 20 Patch objects>)
arr=[11,22,31,15] # 整数--显示四个数各占的百分比
plt.pie(arr)
([<matplotlib.patches.Wedge at 0x1178be1d0>,
<matplotlib.patches.Wedge at 0x1178be6a0>,
<matplotlib.patches.Wedge at 0x1178beb70>,
<matplotlib.patches.Wedge at 0x1178c60f0>],
[Text(0.996424,0.465981,''),
Text(-0.195798,1.08243,''),
Text(-0.830021,-0.721848,''),
Text(0.910034,-0.61793,'')])
arr=[0.2,0.3,0.1] # 小数--表示比例--第一个数占0.2,第二个数占0.3,以此类推...
plt.pie(arr)
([<matplotlib.patches.Wedge at 0x1177d0e80>,
<matplotlib.patches.Wedge at 0x1177da390>,
<matplotlib.patches.Wedge at 0x1177da8d0>],
[Text(0.889919,0.646564,''),
Text(-0.646564,0.889919,''),
Text(-1.04616,-0.339919,'')])
# labels 设置对应的标识
arr=[11,22,31,15]
plt.pie(arr,labels=['a','b','c','d'])
([<matplotlib.patches.Wedge at 0x11794aa90>,
<matplotlib.patches.Wedge at 0x11794af60>,
<matplotlib.patches.Wedge at 0x1179544e0>,
<matplotlib.patches.Wedge at 0x117954a20>],
[Text(0.996424,0.465981,'a'),
Text(-0.195798,1.08243,'b'),
Text(-0.830021,-0.721848,'c'),
Text(0.910034,-0.61793,'d')])
# labeldistance 设置标识到圆心的距离
arr=[11,22,31,15]
plt.pie(arr,labels=['a','b','c','d'],labeldistance=0.3)
([<matplotlib.patches.Wedge at 0x1179e2278>,
<matplotlib.patches.Wedge at 0x1179e2748>,
<matplotlib.patches.Wedge at 0x1179e2c18>,
<matplotlib.patches.Wedge at 0x1179eb198>],
[Text(0.271752,0.127086,'a'),
Text(-0.0533994,0.295209,'b'),
Text(-0.226369,-0.196868,'c'),
Text(0.248191,-0.168526,'d')])
# autopct='%.6f%%' 自动计算出每部分所占的比例,保留六位小数
arr=[11,22,31,15]
plt.pie(arr,labels=['a','b','c','d'],labeldistance=0.3,autopct='%.6f%%')
([<matplotlib.patches.Wedge at 0x117a709e8>,
<matplotlib.patches.Wedge at 0x117a7a128>,
<matplotlib.patches.Wedge at 0x117a7a898>,
<matplotlib.patches.Wedge at 0x117a83048>],
[Text(0.271752,0.127086,'a'),
Text(-0.0533994,0.295209,'b'),
Text(-0.226369,-0.196868,'c'),
Text(0.248191,-0.168526,'d')],
[Text(0.543504,0.254171,'13.924050%'),
Text(-0.106799,0.590419,'27.848101%'),
Text(-0.452739,-0.393735,'39.240506%'),
Text(0.496382,-0.337053,'18.987341%')])
# explode 设置每个部分到圆心的距离
# shadow 设置阴影
arr=[11,22,31,15]
plt.pie(arr,labels=['a','b','c','d'],labeldistance=0.3,shadow=True,explode=[0.2,0.3,0.2,0.4])
([<matplotlib.patches.Wedge at 0x117ab2390>,
<matplotlib.patches.Wedge at 0x117ab2b38>,
<matplotlib.patches.Wedge at 0x117abb390>,
<matplotlib.patches.Wedge at 0x117abbba8>],
[Text(0.45292,0.21181,'a'),
Text(-0.106799,0.590419,'b'),
Text(-0.377282,-0.328113,'c'),
Text(0.579113,-0.393228,'d')])
x = np.array([1,3,5,7,9])
y = x ** 2 - 3
plt.scatter(x,y)
<matplotlib.collections.PathCollection at 0x117c1d780>
Type Markdown and LaTeX: 𝛼2
Type Markdown and LaTeX: 𝛼2
Type Markdown and LaTeX: 𝛼2