import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[1,2,3,4,5]
plt.plot(x,y)
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/销售数量.xls')
x=df["日期"]
y=df["销售数量"]
plt.plot(x,y)
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/销售数量.xls')
x=df["日期"]
y=df["销售数量"]
plt.plot(x,y,color='c',linestyle='dashdot',marker='o',mfc='w')
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/销售数量.xls')
x=df["日期"]
y=df["销售数量"]
fig=plt.figure(figsize=(6,4),facecolor='blue')
plt.plot(x,y)
plt.plot(x,y,color='b',linestyle='-',marker='o',mfc='w')
plt.rcParams['font.sans-serif']='SimHei'
plt.rcParams['axes.unicode_minus']=False
plt.xlabel('2021年8月')
plt.ylabel('销售数量')
plt.xticks(range(1,15,1))
dates=['1日','2日','3日','4日','5日','6日','7日','8日','9日','10日','11日','12日','13日','14日']
plt.xticks(range(1,15,1),dates)
plt.yticks([10,20,30,40,50,60,70,80,90,100,110,120,130,140])
plt.xlim(1,14)
plt.ylim(10,140)
plt.grid()
plt.grid(color='r',linestyle='--',linewidth=1)
for a,b in zip(x,y):
plt.text(a,b+3,'%.1f'%b,ha='center',va='bottom',fontsize=10)
plt.title('1-14日销售数据',fontsize='18')
plt.annotate('关键点',xy=(12,100),xytext=(12,100),xycoords='data',
arrowprops=dict(facecolor='r',shrink=0.01))
plt.legend(('销售数量',),loc='lower right',fontsize=10)
plt.subplots_adjust(left=0.2,bottom=0.2,right=0.9,top=0.9)
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/data.xls')
x1=df['地区']
y1=df['图书']
y2=df['百货']
y3=df['食品']
plt.rcParams['font.sans-serif']='SimHei'
plt.rcParams['xtick.direction']='out'
plt.rcParams['ytick.direction']='in'
plt.title('各地区销售额对比',fontsize='18')
plt.grid(axis='y')
plt.ylabel('销售额')
plt.yticks(range(200,700,50))
plt.plot(x1,y1,label='图书',color='r',marker='p')
plt.plot(x1,y2,label='百货',color='g',marker='.',mfc='r',ms=8,alpha=0.7)
plt.plot(x1,y3,label='食品',color='b',linestyle='-.',marker='*')
plt.legend(['图书','百货','食品'])
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/data.xlsx')
x=df['地区']
height=df['销售额']
plt.rcParams['font.sans-serif']='SimHei'
plt.grid(axis="y",which="major")
plt.xlabel('年份')
plt.ylabel('销售额(万元)')
plt.title('各地区销售额分析',fontsize='18')
plt.bar(x,height,width=0.5,align='center',color='b',alpha=0.5,bottom=0.8)
for a,b in zip(x,height):
plt.text(a,b,format(b,','),ha='center',va='bottom',fontsize=9,color='r',alpha=0.9)
plt.legend(['销售额'])
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/data.xlsx')
x=df['销售额']
plt.rcParams['font.sans-serif']='SimHei'
plt.xlabel('销售额')
plt.ylabel('地区数量')
plt.title("各地区销售额分布直方图")
plt.hist(x,bins=[1000,1200,1300,1400,1500],facecolor="blue",edgecolor="black",alpha=0.7)
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/data.xlsx')
labels=df['地区']
sizes=df['销售额']
plt.rcParams['font.sans-serif']=['SimHei']
plt.figure(figsize=(9,5))
colors=['red','yellow','green','blue']
plt.pie(sizes,
labels=labels,
colors=colors,
labeldistance=1.02,
autopct='%.1f%%',
startangle=90,
radius=0.5,
center=(0.2,0.2),
textprops={'fontsize':9,'color':'k'},
pctdistance=0.6
)
plt.axis('equal')
plt.title('2021年8月各地区销量占比分析')
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/data.xlsx')
x1=df['地区']
y1=df['图书']
y2=df['百货']
y3=df['食品']
plt.rcParams['font.sans-serif']='SimHei'
plt.rcParams['xtick.direction']='out'
plt.rcParams['ytick.direction']='in'
plt.title('各地区销售额对比',fontsize='18')
plt.grid(axis='y')
plt.ylabel('销售额')
plt.yticks(range(200,700,50))
plt.scatter(x1,y1,color='r')
plt.scatter(x1,y2,color='g')
plt.scatter(x1,y3,color='b')
plt.legend(['图书','百货','食品'])
plt.show()
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df=pd.read_excel('C:/Users/Administrator/Desktop/第五章 Matplotlib/data.xlsx')
labels=df['地区']
sizes=list(df['销售额'])
dataLength=len(sizes)
angles=np.linspace(0,
2*np.pi,
dataLength,
endpoint=False
)
angles = np.concatenate((angles,[angles[0]]))
labels=np.concatenate((labels,[labels[0]]))
sizes.append(sizes[0])
plt.polar(angles,
sizes,
'rv--',
linewidth=2
)
plt.fill(angles,
sizes,
facecolor='g',
alpha=0.25
)
plt.thetagrids(angles*180/np.pi,
labels,
fontproperties='simhei'
)
plt.grid(True)
plt.show()