-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from geoneric/gh67
Add plot to visualize pathways using horizontal bars
- Loading branch information
Showing
17 changed files
with
684 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
documentation/use/example/ex_15_bar_plot/05_plot_serial_bar_plot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Bar plot for serial sequence | ||
============================ | ||
""" | ||
|
||
from io import StringIO | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from adaptation_pathways.graph import SequenceGraph, sequence_graph_to_pathway_map | ||
from adaptation_pathways.io import text | ||
from adaptation_pathways.plot import ( | ||
action_level_by_first_occurrence, | ||
init_axes, | ||
plot_bars, | ||
) | ||
|
||
|
||
actions, colour_by_action = text.read_actions( | ||
StringIO( | ||
""" | ||
current #ff4c566a | ||
a #ffbf616a | ||
b #ffd08770 | ||
c #ffebcb8b | ||
""" | ||
) | ||
) | ||
sequences, tipping_point_by_action = text.read_sequences( | ||
StringIO( | ||
""" | ||
current current 2030 | ||
current a 2040 | ||
a b 2050 | ||
b c 2060 | ||
""" | ||
), | ||
actions, | ||
) | ||
sequence_graph = SequenceGraph(sequences) | ||
pathway_map = sequence_graph_to_pathway_map(sequence_graph) | ||
|
||
level_by_action = action_level_by_first_occurrence(sequences) | ||
colour_by_action_name = { | ||
action.name: colour for action, colour in colour_by_action.items() | ||
} | ||
|
||
pathway_map.assign_tipping_points(tipping_point_by_action) | ||
pathway_map.set_attribute("level_by_action", level_by_action) | ||
|
||
arguments = { | ||
"colour_by_action_name": colour_by_action_name, | ||
} | ||
|
||
_, axes = plt.subplots(layout="constrained") | ||
init_axes(axes) | ||
plot_bars(axes, pathway_map, arguments=arguments) | ||
plt.show() |
58 changes: 58 additions & 0 deletions
58
documentation/use/example/ex_15_bar_plot/10_plot_diverging_bar_plot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Pathway map for diverging pathways | ||
================================== | ||
""" | ||
|
||
from io import StringIO | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from adaptation_pathways.graph import SequenceGraph, sequence_graph_to_pathway_map | ||
from adaptation_pathways.io import text | ||
from adaptation_pathways.plot import ( | ||
action_level_by_first_occurrence, | ||
init_axes, | ||
plot_bars, | ||
) | ||
|
||
|
||
actions, colour_by_action = text.read_actions( | ||
StringIO( | ||
""" | ||
current #ff4c566a | ||
a #ffbf616a | ||
b #ffd08770 | ||
c #ffebcb8b | ||
""" | ||
) | ||
) | ||
sequences, tipping_point_by_action = text.read_sequences( | ||
StringIO( | ||
""" | ||
current current 2030 | ||
current a 2040 | ||
current b 2050 | ||
current c 2060 | ||
""" | ||
), | ||
actions, | ||
) | ||
sequence_graph = SequenceGraph(sequences) | ||
pathway_map = sequence_graph_to_pathway_map(sequence_graph) | ||
|
||
level_by_action = action_level_by_first_occurrence(sequences) | ||
colour_by_action_name = { | ||
action.name: colour for action, colour in colour_by_action.items() | ||
} | ||
|
||
pathway_map.assign_tipping_points(tipping_point_by_action) | ||
pathway_map.set_attribute("level_by_action", level_by_action) | ||
|
||
arguments = { | ||
"colour_by_action_name": colour_by_action_name, | ||
} | ||
|
||
_, axes = plt.subplots(layout="constrained") | ||
init_axes(axes) | ||
plot_bars(axes, pathway_map, arguments=arguments) | ||
plt.show() |
62 changes: 62 additions & 0 deletions
62
documentation/use/example/ex_15_bar_plot/15_plot_converging_bar_plot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Pathway map for converging pathways | ||
=================================== | ||
""" | ||
|
||
from io import StringIO | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from adaptation_pathways.graph import SequenceGraph, sequence_graph_to_pathway_map | ||
from adaptation_pathways.io import text | ||
from adaptation_pathways.plot import ( | ||
action_level_by_first_occurrence, | ||
init_axes, | ||
plot_bars, | ||
) | ||
|
||
|
||
actions, colour_by_action = text.read_actions( | ||
StringIO( | ||
""" | ||
current #ff4c566a | ||
a #ffbf616a | ||
b #ffd08770 | ||
c #ffebcb8b | ||
d #ffa3be8c | ||
""" | ||
) | ||
) | ||
sequences, tipping_point_by_action = text.read_sequences( | ||
StringIO( | ||
""" | ||
current current 2030 | ||
current a 2040 | ||
current b 2050 | ||
current c 2060 | ||
a d[1] 2070 | ||
b d[2] 2070 | ||
c d[3] 2070 | ||
""" | ||
), | ||
actions, | ||
) | ||
sequence_graph = SequenceGraph(sequences) | ||
pathway_map = sequence_graph_to_pathway_map(sequence_graph) | ||
|
||
level_by_action = action_level_by_first_occurrence(sequences) | ||
colour_by_action_name = { | ||
action.name: colour for action, colour in colour_by_action.items() | ||
} | ||
|
||
pathway_map.assign_tipping_points(tipping_point_by_action) | ||
pathway_map.set_attribute("level_by_action", level_by_action) | ||
|
||
arguments = { | ||
"colour_by_action_name": colour_by_action_name, | ||
} | ||
|
||
_, axes = plt.subplots(layout="constrained") | ||
init_axes(axes) | ||
plot_bars(axes, pathway_map, arguments=arguments) | ||
plt.show() |
69 changes: 69 additions & 0 deletions
69
documentation/use/example/ex_15_bar_plot/20_plot_example_bar_plot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
Pathway map for an example | ||
========================== | ||
""" | ||
|
||
from io import StringIO | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from adaptation_pathways.graph import SequenceGraph, sequence_graph_to_pathway_map | ||
from adaptation_pathways.io import text | ||
from adaptation_pathways.plot import ( | ||
action_level_by_first_occurrence, | ||
init_axes, | ||
plot_bars, | ||
) | ||
|
||
|
||
actions, colour_by_action = text.read_actions( | ||
StringIO( | ||
""" | ||
current #ff4c566a | ||
a #ffbf616a | ||
b #ffd08770 | ||
c #ffebcb8b | ||
d #ffa3be8c | ||
e #ffb48ead | ||
f #ff5e81ac | ||
""" | ||
) | ||
) | ||
sequences, tipping_point_by_action = text.read_sequences( | ||
StringIO( | ||
""" | ||
current current 2030 | ||
current a 2040 | ||
a e[1] 2090 | ||
current b 2050 | ||
b f[1] 2080 | ||
current c 2060 | ||
c f[2] 2080 | ||
current d 2070 | ||
d f[3] 2080 | ||
f[1] e[2] 2090 | ||
f[2] e[3] 2090 | ||
f[3] e[4] 2090 | ||
""" | ||
), | ||
actions, | ||
) | ||
sequence_graph = SequenceGraph(sequences) | ||
pathway_map = sequence_graph_to_pathway_map(sequence_graph) | ||
|
||
level_by_action = action_level_by_first_occurrence(sequences) | ||
colour_by_action_name = { | ||
action.name: colour for action, colour in colour_by_action.items() | ||
} | ||
|
||
pathway_map.assign_tipping_points(tipping_point_by_action) | ||
pathway_map.set_attribute("level_by_action", level_by_action) | ||
|
||
arguments = { | ||
"colour_by_action_name": colour_by_action_name, | ||
} | ||
|
||
_, axes = plt.subplots(layout="constrained") | ||
init_axes(axes) | ||
plot_bars(axes, pathway_map, arguments=arguments) | ||
plt.show() |
75 changes: 75 additions & 0 deletions
75
documentation/use/example/ex_15_bar_plot/25_plot_example_bar_plot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
Pathway map for an example | ||
========================== | ||
""" | ||
|
||
from io import StringIO | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from adaptation_pathways.graph import SequenceGraph, sequence_graph_to_pathway_map | ||
from adaptation_pathways.io import text | ||
from adaptation_pathways.plot import ( | ||
action_level_by_first_occurrence, | ||
init_axes, | ||
plot_bars, | ||
) | ||
|
||
|
||
actions, colour_by_action = text.read_actions( | ||
StringIO( | ||
""" | ||
current #ff4c566a | ||
a #ffbf616a | ||
b #ffd08770 | ||
c #ffebcb8b | ||
d #ffa3be8c | ||
""" | ||
) | ||
) | ||
sequences, tipping_point_by_action = text.read_sequences( | ||
StringIO( | ||
""" | ||
current current 2030 | ||
current a[1] 2100 | ||
current b[1] 2040 | ||
b[1] a[2] 2100 | ||
b[1] c[2] 2050 | ||
c[2] b[2] 2070 | ||
b[2] a[3] 2100 | ||
c[2] a[4] 2100 | ||
c[2] d[3] 2100 | ||
b[1] d[2] 2100 | ||
current c[1] 2050 | ||
c[1] b[3] 2070 | ||
b[3] a[5] 2100 | ||
c[1] a[6] 2100 | ||
c[1] d[4] 2100 | ||
current d[1] 2100 | ||
""" | ||
), | ||
actions, | ||
) | ||
sequence_graph = SequenceGraph(sequences) | ||
pathway_map = sequence_graph_to_pathway_map(sequence_graph) | ||
|
||
level_by_action = action_level_by_first_occurrence(sequences) | ||
colour_by_action_name = { | ||
action.name: colour for action, colour in colour_by_action.items() | ||
} | ||
|
||
pathway_map.assign_tipping_points(tipping_point_by_action) | ||
pathway_map.set_attribute("level_by_action", level_by_action) | ||
|
||
arguments = { | ||
"colour_by_action_name": colour_by_action_name, | ||
} | ||
|
||
_, axes = plt.subplots(layout="constrained") | ||
init_axes(axes) | ||
plot_bars(axes, pathway_map, arguments=arguments) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Examples of bar plots | ||
===================== |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.