-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarplot_vertical.py
More file actions
executable file
·109 lines (90 loc) · 2.54 KB
/
barplot_vertical.py
File metadata and controls
executable file
·109 lines (90 loc) · 2.54 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""
Plot a vertical standing barplot. requires modification
"""
import sys
import numpy as np
import polars as pl
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import rcParams
import matplotlib.font_manager as fm
# set font
arial_font = "/home/james/Downloads/arial.ttf"
arial_font_bold = "/home/james/Downloads/Arial Bold.ttf"
fm.fontManager.addfont(arial_font)
fm.fontManager.addfont(arial_font_bold)
rcParams["font.sans-serif"] = "Arial"
rcParams["font.family"] = "Arial"
rcParams["font.size"] = 10
# import table
file = sys.argv[1]
# file = "./nife_boltz_covm00_id70_cifs_clusterslist.tsv"
df = pl.read_csv(
file,
separator="\t",
has_header=False,
new_columns=["cluster_rep", "count"],
)
y = "cluster_rep"
x = "count"
# plot barplot
fig, ax = plt.subplots(figsize=(6, 8))
ax = sns.barplot(
df,
x=x,
y=y,
linewidth=1,
# color="darkgrey",
# color="lightskyblue",
color="#81c8be",
# color="#ef9f76",
edgecolor="black",
alpha=1.0,
)
# add numbers to each bar
# ax.bar_label(ax.containers[0], padding=6)
for bar in ax.patches:
width = bar.get_width()
ypos = bar.get_y() + bar.get_height() / 2
# make bar labels with comma separated integers
label = f"{width:,.0f}"
pad = 100
if width > 3000:
ax.text(
width - pad,
ypos,
label,
va="center",
ha="right",
color="whitesmoke",
fontweight="bold",
)
else:
ax.text(width + pad, ypos, label, va="center", ha="left", color="black")
# else:
# ax.bar_label(ax.containers[0], padding=6)
# ax.text(width + 1, ypos, label, va="center", ha="right", color="black")
# remove top and right spines, and trim spines
sns.despine(offset=5, trim=True)
# change spine and axis positions
ax.tick_params(axis="y", length=0)
ax.spines["left"].set_visible(False)
ax.spines["bottom"].set_visible(True)
ax.spines["bottom"].set_position(("outward", 5))
ax.xaxis.set_label_position("bottom")
# set title and axis labels
plt.suptitle(
"[NiFe] LSU proteins clustered by structural similarity", fontsize=10, y=1.000
)
ax.set_ylabel("Cluster represetative i.d.", labelpad=15, fontsize=10)
ax.set_xlabel("Clustered proteins", labelpad=8, fontsize=10)
# set number of ticks
ax.tick_params(axis="x", rotation=90)
t = np.arange(0, 3501, 1000)
ax.set_xticks(ticks=t, minor=False)
# ax.set_xticks([0, 500, 1500, 2500, 3500], minor=False)
# plot
plt.tight_layout()
plt.savefig("./barplot.png", format="png", dpi=300)
plt.show()