python 分布图_python数据分布型图表柱形分布图系列带误差线的柱形图
柱形分布圖系列
柱形分布圖系列
使用柱形圖的方式展示數(shù)據(jù)的分布規(guī)律;
可以借助誤差線或散點(diǎn)圖;
帶誤差線的柱形圖就是使用每個(gè)類別的均值作為柱形的高度;
再根據(jù)每個(gè)類別的標(biāo)準(zhǔn)差繪制誤差線;
缺點(diǎn):無(wú)法顯示數(shù)據(jù)的分布情況;
可以在帶誤差線的柱形圖的基礎(chǔ)上,添加抖動(dòng)散點(diǎn)圖;
優(yōu)點(diǎn):可以方便觀察數(shù)據(jù)分布規(guī)律;
繪制柱形分布圖系列
帶誤差線柱形圖使用statsummary(fundata='meansdl',geom='bar')實(shí)現(xiàn)柱形圖;使用statsummary(fundata='meansdl',geom='errorbar')實(shí)現(xiàn)誤差線繪制;再使用geom_jitter()函數(shù)添加抖動(dòng)散點(diǎn)圖;
繪制帶誤差線的柱形圖
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from plotnine import *
df=pd.read_csv('d:\python\out\DistributionD.csv')
df['class']=df['class'].astype("category",["n", "s", "k", "mm"])
#帶誤差線的柱形圖
Barjitter_plot=(ggplot(df,aes(x='class',y="value",fill="class"))
+stat_summary(fun_data="mean_sdl",fun_args = {'mult':1},
geom="bar", color = "black",size = 0.75,width=0.7,show_legend=False)
+stat_summary(fun_data="mean_sdl", fun_args = {'mult':1},
geom="errorbar", color = "black",size = 0.75,width=.2,show_legend=False)
+scale_fill_hue(s = 0.90, l = 0.65, h=0.0417,color_space='husl')
+ylim(0,7)
+theme_matplotlib()
+theme(aspect_ratio =1.05,
dpi=100,
figure_size=(4,4)))
print(Barjitter_plot)
Barjitter_plot.save("d:\python\out\Barjitter_plot.pdf")
繪制帶誤差線柱形與抖動(dòng)散點(diǎn)圖;
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from plotnine import *
df=pd.read_csv('d:\python\out\DistributionD.csv')
df['class']=df['class'].astype("category",["n", "s", "k", "mm"])
#帶誤差線柱形與抖動(dòng)圖
Barjitter_plot2=(ggplot(df,aes(x='class',y="value",fill="class"))
+stat_summary(fun_data="mean_sdl", fun_args = {'mult':1},
geom="bar", fill="w",color = "black",size =0.75,width=0.7,show_legend=False)
+stat_summary(fun_data="mean_sdl",fun_args = {'mult':1},
geom="errorbar", color = "black",size = 0.75,width=.2,show_legend=False)
+geom_jitter(width=0.3,size=2,stroke=0.1,shape='o',show_legend=False)
+scale_fill_hue(s = 0.90, l = 0.65, h=0.0417,color_space='husl')
+ylim(0,7)
+theme_matplotlib()
+theme(aspect_ratio =1.05,
dpi=100,
figure_size=(4,4)))
print(Barjitter_plot2)
Barjitter_plot.save("d:\python\out\Barjitter_plot2.pdf")
總結(jié)
以上是生活随笔為你收集整理的python 分布图_python数据分布型图表柱形分布图系列带误差线的柱形图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Apizza-绑定数据模型
- 下一篇: JAVA自学之路