折线图
import pandas as pd
import pylab as plt
plt.rc('font',family='SimHei')
plt.rc('font',size=16)
a=pd.read_excel("data2_52.xlsx",header=None)
b=a.values
x=b[0]
y=b[1:]
plt.plot(x,y[0],'-*b',label='钻石')
plt.plot(x,y[1],'--dr',label='铂金')
plt.xlabel('月份');plt.ylabel('每月销量')
plt.legend(loc='upper left');plt.grid();plt.show()
生成的图像如上图
柱状图
import pandas as pd
import pylab as plt
plt.rc('font',family='Simhei')
plt.rc('font',size=16)
a=pd.read_excel("data2_52.xlsx",header=None)
b=a.T;b.plot(kind='bar');plt.legend(['钻石','铂金'])
plt.xticks(range(6),b[0],rotation=0)
plt.ylabel('数量');plt.show()
标准圆
import pandas as pd
import pylab as plt
t=plt.linspace(10,20,100)
x=plt.cos(t)
y=plt.sin(t)
plt.plot(x,y)
plt.axis("equal")
plt.show()
饼形图、柱状图、曲线图
import pandas as pd
import pylab as plt
import numpy as np
# plt.rc('text',usetex=True)
y1=np.random.randint(2,5,6);
y1=y1/sum(y1);plt.subplot(221);
str=['apple','grape','peach','pear','banana','pineapple']
plt.barh(str,y1)
plt.subplot(222);plt.pie(y1,labels=str)
plt.subplot(212)
x2=np.linspace(0.01,10,100);
y2=np.sin(10*x2)/x2
plt.plot(x2,y2);plt.xlabel('$x$')
plt.ylabel('$\\mathrm{sin}(10x)/x$');plt.show()