-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.py
86 lines (76 loc) · 2.76 KB
/
box.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Ming
# @Date: 2019-07-12 16:01:58
# @Last Modified by: MingJia
# @Last Modified time: 2019-10-16 10:54:17
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import click
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('-i', '--input',
required=True,
type=click.Path(),
help="The table input to plot box")
@click.option('--xname',
required=True,
help="The x column name for the plot.")
@click.option('--yname',
required=True,
help="The y column name for the plot.")
@click.option('--huename',
required=False,
help="The hue column name for the plot.")
@click.option('--xorder',
required=False,
help="The order of x axis names(sep by ,)")
@click.option('--hueorder',
required=False,
help="The order of hue names(sep by ,).")
@click.option('--huecolors',
required=False,
help="The colors for hue infos(sep by ,).")
@click.option('-y', '--ylab',
required=False,
help="The ylab for the plot.")
@click.option('-t', '--title',
required=False,
help="The title for the plot.")
@click.option('--xrotation',
default=0,
type=int,
show_default=True,
help="The x ticks lable rotation.")
@click.option('--showfliers',
default=False,
type=click.BOOL,
show_default=True,
help="Whether show the fliers")
@click.option('-p', '--prefix',
default='result',
help="The out prefix.")
def cli(input, xname, yname, huename, xorder, hueorder, huecolors, ylab, title,
xrotation, showfliers, prefix):
"""
Box plot with python.
"""
df = pd.read_csv(input, sep='\t')
x_order = xorder.strip().split(',') if xorder else None
hue_order = hueorder.strip().split(',') if hueorder else None
hue_color = huecolors.strip().split(',') if huecolors else None
# Draw
figure, axis = plt.subplots(figsize=(16, 8), dpi=300)
sns.boxplot(data=df, x=xname, y=yname, hue=huename, order=x_order,
showfliers=showfliers, hue_order=hue_order, color=hue_color,
width=0.6, ax=axis)
axis.set_xticklabels(axis.get_xticklabels(), rotation=xrotation)
axis.set(xlabel="", ylabel=ylab)
axis.set_title(title, fontdict={'size': 22})
plt.savefig(prefix + '.svg', bbox_inches='tight')
plt.savefig(prefix + '.png', dpi=300, bbox_inches='tight')
if __name__ == "__main__":
cli()