-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.py
60 lines (54 loc) · 1.71 KB
/
plots.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
import plotly.graph_objects as go
# Function to create the bar plot
def generate_bar_plot(x, y, error_y=None):
fig = go.Figure()
fig.add_trace(go.Bar(
x=x,
y=y,
error_y=dict(type='data', array=error_y, visible=error_y is not None)
))
fig.update_layout(
title="Coverage Bar Plot",
xaxis_title="X-Axis",
yaxis_title="Y-Axis",
plot_bgcolor='#2c2f34',
paper_bgcolor='#1e1e1e',
font_color="white"
)
return fig
# Function to create a Sankey plot
def generate_sankey_plot(nodes, links):
"""
Generates a Sankey plot using nodes and links.
Args:
nodes (list): List of node names (taxonomic levels).
links (dict): Dictionary containing 'source', 'target', and 'value' lists.
Returns:
Plotly figure object.
"""
try:
fig = go.Figure(data=[go.Sankey(
node=dict(
pad=15,
thickness=20,
line=dict(color="black", width=0.5),
label=nodes
),
link=dict(
source=links["source"],
target=links["target"],
value=links["value"]
)
)])
# Update layout
fig.update_layout(
title_text="Taxonomic Classification Sankey",
font_size=10
)
return fig
except KeyError as e:
print(f"KeyError in generate_sankey_plot: {e}")
return go.Figure().update_layout(title=f"Error: Missing key {e}")
except Exception as e:
print(f"Error in generate_sankey_plot: {e}")
return go.Figure().update_layout(title=f"Error: {e}")