*各种图形的label参数都与plt.legend函数配合使用
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#更改文件存放提取路径
import os
os.chdir('')
data = pd.read_csv()
#数据按照地区求销量平均值
data_1 = data.groupby('Region').mean()['Sales']
x_data = data_1.values
y_label = data_1.index #y轴标签为数据第一行指标
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
饼图不适合取值过多的分类特征
pie(x,explode,labels,colors,autopct=,pctdistance,shadow,labeldistance,startangle,radius,wedgeprops,textprops,center)
explode = [0,0.1,0,0,0,0.2]
colors = ['yellow','red','purple','green','blue','darkred']
plt.pie(x=x_data,explode=explode,labels=y_label,colors=colors,autopct='.if%%',pctdistance=1.1,
wedgeprops={
'linewidth':1.5,'edgecolor':'green'},textprops={
'fontsize':10,'color':'black'})
plt.title('标题',pad=30)
plt.show()
bar(x,height,width,bottom,edge,color,linewidth,tick_label,align)
data = [115,130,100,140]
plt.bar(x=range(1,5), height=data, align='center', color='yellow')
plt.xlabel('地区')
plt.ylabel('销量')
plt.title('不同地区的销量',pad = 15) #pad为标题与图表距离,一般15-30之间
plt.xlim(0,5)
plt.show()
plt.hist(x,bins,width,color,linewidth,tick_label,align,density=True/False)
data = np.random.randn(10000)
plt.hist(x = data, bins = 30, color = 'purple',edgecolor = 'black' ,density = False)
plt.show()
plt.scatter(x,y,s,color,marker,cmap,norm,alpha,linewidths,edgecolors)
data1 = np.random.randn(10)
data2 = np.random.randn(10)
plt.scatter(x=data1, y=data2, color='steelblue', marker='o', s=100)
plt.show()
观察数据分散情况(是否有异常值)
plt.boxplot(x, notch, sym, vert, whis, positions, widths, patch_artist, meanline, showmeans, boxprops, labels, flierprops)
即为plt.plot()函数