Package: plotly-signif
plotly-signifA python class of drawing a Bar/Box plot based on the plotly package, with freely definable statistical annotationsHow to useDownloadUsepippipinstallplotly-signifYou can import like this:fromplotly_signifimportplotly_signif# orfromplotly_signifimport*Download theplotly_signif.pyto the path of your programfromplotly_signifimport*Enjoy itBarYou can refer to the following example :fromplotly_signifimport*importpandasaspdiris=pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')df1=iris.groupby("species").mean()df2=iris.groupby("species").sem()test=plotly_signif(data=df1,error=df2,text={"x":"X","y":"Y"})test.plot()# 添加统计注释annotation_list=[[0,1,1],[2,0,3,-1],[2,1,2,2],[0,1,3,6],[0,2,3,9]]test.add_annotations(annotation_list=annotation_list,text="***",inne_color="#B799FF")test.add_annotations(annotation_list=[[1,2,3,3]],text="🏅",sign_d_index=2)test.add_annotations(annotation_list=[[1,1,2,4]],text="😭",sign_d_index=2)test.add_annotations(annotation_list=[[1,0,2,2]],text="⭐⭐⭐",sign_d_index=2,size=12)test.add_annotations(annotation_list=[[1,2,0]],text="ns",size=14,sign_d_index=2.5)# 绘制/保存test.show("./image/example.png")# 保存使用属性 save_path = "./image/example.png"test2=plotly_signif(data=df1,error=df2,text={"x":"X","y":"Y"})test2.set_color(["#453C67","#6D67E4",'#B799FF','#ACBCFF'])# change the colorstest2.plot(pic_px=[580,650])# An example of changing labels based on plotly syntaxtest2.fig.update_layout(title=dict(# set the titletext="Test 2",font={'size':20},x=0.5,y=0.9,),)test2.fig.update_layout(# set the side labelslegend=dict(orientation="h",x=0.12,y=-0.15,traceorder="normal",font=dict(size=16),),)test2.add_annotations(annotation_list=[[0,1,3,6]],text="🧠",sign_d_index=2)test2.add_annotations(annotation_list=[[0,0,3,3]],text="❓",sign_d_index=2)test2.add_annotations(annotation_list=[[1,0,0,2.3]],text="👽",sign_d_index=2,inne_color="#FFFFFF")test2.add_annotations(annotation_list=[[1,2,2,5]],text="🤖",sign_d_index=2,inne_color="#FFFFFF")test2.add_annotations(annotation_list=[[1,1,1,7.6]],text="🐵",sign_d_index=2,inne_color="#FFFFFF")test2.add_annotations(annotation_list=[[1,3,3,10]],text="🐁",sign_d_index=2,inne_color="#FFFFFF")test2.show()Boxdata=pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/fmri.csv')subjecttimepointeventregionsignal0s1318stimparietal-0.0175521s514stimparietal-0.0808832s1218stimparietal-0.0810333s1118stimparietal-0.0461344s1018stimparietal-0.037970..................1059s08cuefrontal0.0181651060s137cuefrontal-0.0291301061s127cuefrontal-0.0049391062s117cuefrontal-0.0253671063s00cueparietal-0.006899Box_test=plotly_signif(data=data,text={"x":"Region","y":"Signal"},mode="Box")Box_test.plot(pic_px=[840,620],Box_list=["subject","region","signal"])annotation_list=[[0,1,0],[0,0,2,1],[0,2,5,4],[1,3,4,5]]Box_test.add_annotations(annotation_list=annotation_list)Box_test.fig.update_layout(title_text="Seaborn-data-fmri groupby subject")Box_test.show()Parameter explanation🌀 You can use plotly's syntax to set theobject.fig, new settings will overwrite the default settings.__init__:data :Data frame used for drawing bar charterror :Data frame corresponding to error bars, only used withmode = "Bar"text :Image text labelmode :default = "Bar", and supports "Box" to plotplot()pic_px :image size list , [width,height] , The unit is pxBox_list :If a box plot is drawn, the meaning of this list is["which Group","which x","which y"]add_annotations()annotation_list :A two-dimensional list representing the position of the annotation, with each sublist representing an annotation. The length of 3 is the inter-group annotation, the length of 4 is the intra-group annotation, and the last value controls the y-axis position.[0,1,1]means that the annotation is between the 1/2th group, and the y-axis position drops 1 level relative to y_max;[2,0,3,-1]means that the annotation is within the 3rd group, and within the group In the 1/4th column, the y-axis position rises one level relative to y_max.表示注释在什么位置的二维列表，每一个子列表表示一个注释。长度为3的是组间注释，长度4为组内注释，最后一个值控制y轴位置。[0,1,1]表示注释在第1/2个组之间，y轴位置相对于 y_max 下降1层；[2,0,3,-1]表示注释在第3个组内，组内的第1/4个柱间，y轴位置相对于 y_max 上升一层。text :annotation symbol,default = "***", which can also be 🪙🆙🏅⭐🔥🍋💔😃😭 ... symbols, visiblehttps://www.emojiall.com/zh-hans/copysize :symbol font size,default = 16line_width :line width,default = 1.5color :intergroup annotation color,default = 'rgba(0,0,0,1)'inne_color :annotation color within group,default = "rgba(100,100,100,1)"y_max_index :The y-height of the annotation when layer is set to 0,default = 1.15, multiply the height of the tallest bar in the chart by y_max_index to get y_maxlayer_down_index :control the spacing between upper and lower layers,default = 0.08, layer_down = layer_down_index $ \times $ y_maxsign_d_index :distance between line and symbol,default = 4, layer_down / sign_d_indexline_d_index :the length of the hanging line,default = 3.2, layer_down / line_d_indexshow()save_path :path to save.set_color(): set the color of the column, given a listset_color()need before useplot()TODOSupports boxplotsSupports horizontal drawingrequirementnumpypandasplotlykaleido  (There may be problems with the installation of this package)Any feedback on bugs or suggestions for features are welcome