Skip to main content

A python class of drawing a Bar/Box plot based on the plotly package, with freely definable statistical annotations

Project description

plotly-signif

A python class of drawing a Bar/Box plot based on the plotly package, with freely definable statistical annotations

How to use

Download

  • Use pip
pip install plotly-signif

You can import like this:

from plotly_signif import plotly_signif
# or
from plotly_signif import *
  • Download the plotly_signif.py to the path of your program
  from plotly_signif import *
  • Enjoy it

Bar

You can refer to the following example :

from plotly_signif import *
import pandas as pd
iris = 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 colors
test2.plot(pic_px=[580,650])
# An example of changing labels based on plotly syntax
test2.fig.update_layout(
    title = dict(  # set the title
        text = "Test 2",
        font = {'size': 20},
        x = 0.5,
        y = 0.9,
        ),
)
test2.fig.update_layout(   # set the side labels
                legend=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()

Box

data = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/fmri.csv')


    subject	timepoint	event	region	signal
0	s13	18	stim	parietal	-0.017552
1	s5	14	stim	parietal	-0.080883
2	s12	18	stim	parietal	-0.081033
3	s11	18	stim	parietal	-0.046134
4	s10	18	stim	parietal	-0.037970
...	...	...	...	...	...
1059	s0	8	cue	frontal	0.018165
1060	s13	7	cue	frontal	-0.029130
1061	s12	7	cue	frontal	-0.004939
1062	s11	7	cue	frontal	-0.025367
1063	s0	0	cue	parietal	-0.006899
Box_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 the object.fig , new settings will overwrite the default settings.

  • __init__ :
    • data : Data frame used for drawing bar chart
    • error : Data frame corresponding to error bars, only used with mode = "Bar"
    • text : Image text label
    • mode : default = "Bar" , and supports "Box" to plot
  • plot()
    • pic_px : image size list , [width,height] , The unit is px
    • Box_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, visible https://www.emojiall.com/zh-hans/copy

    • size : symbol font size, default = 16

    • line_width : line width, default = 1.5

    • color : 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_max

    • layer_down_index : control the spacing between upper and lower layers, default = 0.08 , layer_down = layer_down_index $ \times $ y_max

    • sign_d_index : distance between line and symbol, default = 4 , layer_down / sign_d_index

    • line_d_index : the length of the hanging line, default = 3.2 , layer_down / line_d_index

  • show()
    • save_path : path to save.
  • set_color() : set the color of the column, given a list set_color() need before use plot()

TODO

  • Supports boxplots
  • Supports horizontal drawing

requirement

  • numpy
  • pandas
  • plotly
  • kaleido (There may be problems with the installation of this package)

Any feedback on bugs or suggestions for features are welcome

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plotly-signif-0.0.41.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plotly_signif-0.0.41-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file plotly-signif-0.0.41.tar.gz.

File metadata

  • Download URL: plotly-signif-0.0.41.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for plotly-signif-0.0.41.tar.gz
Algorithm Hash digest
SHA256 b3da08fc44c9abe5e8910f17973152efc2c44b967a06551443147c1bfc05083c
MD5 6a24b2b045029c0e1cb8de30051c019e
BLAKE2b-256 031197cdaf23b51c29ad0605796d0aff62b6e5d5c1eb5423c148171bd3ddfc23

See more details on using hashes here.

File details

Details for the file plotly_signif-0.0.41-py3-none-any.whl.

File metadata

  • Download URL: plotly_signif-0.0.41-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for plotly_signif-0.0.41-py3-none-any.whl
Algorithm Hash digest
SHA256 163212deac02add464332a81190df076711b9a3bb07deade238822d11e2e1304
MD5 4f07f73faa35a9a8131004c4eb3ac1e2
BLAKE2b-256 701f50c2a91f135b8693c69301ca3b31df967e65fa9a8e1a603fe92e5df8fda5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page