plt.plot(x, y, ls="-", lw = 2, label = "plot figure")
plt.scatter(x,y,c="b",label="scatterfigure")
plt.xlim(xmin,xmax)
plt.xlabel(string)
plt.grid(linestyle=":",color="r")
plt.axhline(y=0.0,c="r",ls="--",lw=2)
plt.axvspan(xmin=1.0,xmax=2.0,facecolor="y",alpha=0.3)。
plt.annotate(string,xy=(np.pi/2,1.0),xytext = ((np.pi/2)+0.15,1.5),weight="bold",color="b",arrowprops=dict(arrowstyle="->",connectionstyle="arc3",color="b"))
plt.text(x,y,string,weight="bold",color="b")
plt.title(string)
plt.legend(loc="lower left")
plt.bar(x,y)
plt.barh(x,y)
于柱状图不同的地方在于,它更像折线图一样是连续的。
plt.hist(x)
plt.pie(x)
plt.polar(theta,r)
plt.scatter(x,y)
plt.boxplot(x)
plt.errorbar(x,y,yerr=a,xerr=b)
定性数据的分布展示
bar(x,y,align="center",color="b",tick_label=["A","B","C","D","E"],alpha=0.6)
注意:柱状图适合离散数据,当为连续数据时,很容易使数据“无法显示”,因为x轴太多而导致间隔太大,显示不出
方法1:重新设置一个索引,不以datetime作为轴
df.reset_index(inplace=True)
方法2:理论上来说,将datetime重新变成离散的str或object也可行,不过我试了一下
#转换为obj不行
df['dt'] = df['dt'].astype('object')
如果有懂的大佬麻烦解决一下
barh(x,y,align="center",color="k",tick_label=["A","B","C","D","E"])
plt.bar(x,y,align="center",color="#66c2a5",tick_label=["A","B","C","D","E"],label="班级A") plt.bar(x,y1,align="center",bottom=y,color="#8da0cb",label="班级B")
plt.barh(x,y,align="center",color="#66c2a5",tick_label=["A","B","C","D","E"],label="班级A") plt.barh(x,y1,align="center",left=y,color="#8da0cb",label="班级B")
plt.bar(x,y,bar_width,color="c",align="center",label="班级A",alpha=0.5) plt.bar(x+bar_width,y1,bar_width,color="b",align="center",label="班级B",alpha=0.5)
plt.barh(x,y,bar_width,color="c",align="center",label="班级A",alpha=0.5) plt.barh(x+bar_width,y1,bar_width,color="b",align="center",label="班级B", alpha=0.5)
plt.bar(x,y,align="center",color="c",tick_label=["A","B","C","D","E"],ha tch="///")
plt.stackplot(x,y,y1,y2,labels=labels,colors=colors)
plt.broken_barh([(30,100),(180,50),(260,70)],(20,8),facecolors="#1f78b4") plt.broken_barh([(60,90),(190,20),(230,30),(280,60)],(10,8),facecolors=("#7fc97f","#beaed4","#fdc086","#ffff99"))
plt.step(x,y,color="#8dd3c7", where="pre",lw=2)
hist(x,bins=bins,color="b",histtype="bar",label="score",rwidth=10)
plt.hist(x,bins=bins,color=colors,histtype="bar",rwidth=10,stacked=True,label=labels)
plt.hist(x,bins=bins,color=colors,histtype="stepfilled",rwidth=10,stacked=True,label=labels)
定性数据的比例展示
pie(students,explode=explode,labels=labels,autopct="%3.1f%%",startangle=45,shadow=True,colors=colors)
bplot = plt.boxplot(testList,whis=whis,widths=width,sym="o",labels=labels,patch_artist=True)
plt.boxplot(x,vert=False)
定量数据的误差范围
误差棒的计算方法可以有很多种:单一数值、置信区间、标准差和标准误等
plt.errorbar(x,y,yerr=error_limit,fmt=":o",ecolor="y",elinewidth=4,ms=5,mfc="c",mec='r',capthick=1,capsize=2)
error_attri =dict(elinewidth=2,ecolor="black",capsize=3)
plt.bar(x,y,color="c",width=0.6,align="center",yerr=std_err,error_kw=error_attri,tick_label=["园区1","园区2","园区3","园区4","园区5"])
plt.legend(loc="upper left",bbox_to_anchor=(0.05,0.95),ncol=3,title="powerfunction",shadow=True,fancybox=True)
plt.title("Left Demo",loc="left",fontdict={"size":"xx-large","color":"r","family":"Times New Roman"})plt.title("right demo",loc="right",family="Comic Sans MS",size=20,style="oblique",color="c")