Skip to content

Commit

Permalink
Merge pull request #48 from geoneric/gh40
Browse files Browse the repository at this point in the history
Replace current function by a custom plotting function
  • Loading branch information
kordejong authored Dec 6, 2024
2 parents 8b434a5 + 250e1a2 commit 5c8e94e
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
pathway_map.set_attribute("level_by_action", level_by_action)
pathway_map.set_attribute("colour_by_action_name", colour_by_action_name)

arguments = {
"colour_by_action_name": colour_by_action_name,
}

_, axes = plt.subplots(layout="constrained")
init_axes(axes)
plot_classic_pathway_map(axes, pathway_map)
plot_classic_pathway_map(axes, pathway_map, arguments=arguments)
plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
pathway_map.set_attribute("level_by_action", level_by_action)
pathway_map.set_attribute("colour_by_action_name", colour_by_action_name)

arguments = {
"colour_by_action_name": colour_by_action_name,
}

_, axes = plt.subplots(layout="constrained")
init_axes(axes)
plot_classic_pathway_map(axes, pathway_map)
plot_classic_pathway_map(axes, pathway_map, arguments=arguments)
plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
pathway_map.set_attribute("level_by_action", level_by_action)
pathway_map.set_attribute("colour_by_action_name", colour_by_action_name)

arguments = {
"colour_by_action_name": colour_by_action_name,
}

_, axes = plt.subplots(layout="constrained")
init_axes(axes)
plot_classic_pathway_map(axes, pathway_map)
plot_classic_pathway_map(axes, pathway_map, arguments=arguments)
plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
pathway_map.set_attribute("level_by_action", level_by_action)
pathway_map.set_attribute("colour_by_action_name", colour_by_action_name)

arguments = {
"colour_by_action_name": colour_by_action_name,
}

_, axes = plt.subplots(layout="constrained")
init_axes(axes)
plot_classic_pathway_map(axes, pathway_map)
plot_classic_pathway_map(axes, pathway_map, arguments=arguments)
plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@
pathway_map.set_attribute("level_by_action", level_by_action)
pathway_map.set_attribute("colour_by_action_name", colour_by_action_name)

arguments = {
"colour_by_action_name": colour_by_action_name,
}

_, axes = plt.subplots(layout="constrained")
init_axes(axes)
plot_classic_pathway_map(axes, pathway_map)
plot_classic_pathway_map(axes, pathway_map, arguments=arguments)
plt.show()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ profile = "black"

[tool.pylint]
disable = "C0103, C0114, C0115, C0116, C0302, E0401, W0212, W0511, R0801"
max-line-length=240
extension-pkg-allow-list = [
"matplotlib",
"PySide6",
Expand Down
46 changes: 37 additions & 9 deletions source/package/adaptation_pathways/cli/plot_pathway_map.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os.path
import sys
import typing

import docopt
import matplotlib.pyplot as plt
Expand All @@ -13,10 +14,15 @@


@main_function
def plot_map(basename_pathname: str, plot_pathname: str) -> int:
def plot_map(
basename_pathname: str,
plot_pathname: str,
*,
arguments,
) -> int:

# pylint: disable-next=unused-variable
actions, sequences, tipping_point_by_action, colour_by_action = read_dataset(
_, sequences, tipping_point_by_action, colour_by_action = read_dataset(
basename_pathname
)

Expand All @@ -35,7 +41,11 @@ def plot_map(basename_pathname: str, plot_pathname: str) -> int:

_, axes = plt.subplots(layout="constrained")
init_axes(axes)
plot_classic_pathway_map(axes, pathway_map, title="Pathway map")

# TODO This should be colour_by_action
arguments["colour_by_action_name"] = colour_by_action_name

plot_classic_pathway_map(axes, pathway_map, arguments=arguments)
save_plot(plot_pathname)

return 0
Expand All @@ -47,7 +57,8 @@ def main() -> int:
Plot pathway map
Usage:
{command} <basename> <plot>
{command} [--title=<title>] [--x_label=<label>] [--show_legend]
[--overshoot] <basename> <plot>
Arguments:
basename Either, the name without postfix and extension of text
Expand All @@ -60,6 +71,11 @@ def main() -> int:
Options:
-h --help Show this screen and exit
--version Show version and exit
--overshoot Show tipping points as overshoots, extending a little
bit beyond the actual point
--show_legend Show legend
--title=<title> Title
--x_label=<label> Label of x-axis
The format for storing sequences is simple: per line mention the names of
two actions that form a sequence. Information from multiple lines can result
Expand All @@ -70,12 +86,24 @@ def main() -> int:
{command} serial serial.pdf
{command} serial.apw serial.pdf
"""
arguments = sys.argv[1:]
arguments = docopt.docopt(usage, arguments, version=version)
basename_pathname = arguments["<basename>"] # type: ignore
plot_pathname = arguments["<plot>"] # type: ignore
arguments = docopt.docopt(usage, sys.argv[1:], version=version)
basename_pathname = arguments["<basename>"]
plot_pathname = arguments["<plot>"]
title = arguments["--title"] if arguments["--title"] is not None else ""
x_label = arguments["--x_label"] if arguments["--x_label"] is not None else ""
show_legend = arguments["--show_legend"]
overshoot = arguments["--overshoot"]

plot_arguments: dict[str, typing.Any] = {
"title": title,
"x_label": x_label,
"show_legend": show_legend,
}

if overshoot:
plot_arguments["tipping_point_overshoot"] = 0.4

if len(os.path.splitext(plot_pathname)[1]) == 0:
plot_pathname += ".pdf"

return plot_map(basename_pathname, plot_pathname)
return plot_map(basename_pathname, plot_pathname, arguments=plot_arguments)
15 changes: 3 additions & 12 deletions source/package/adaptation_pathways/desktop/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
from ..plot import (
pathway_graph_node_colours,
pathway_map_edge_colours,
pathway_map_edge_styles,
pathway_map_node_colours,
pathway_map_node_styles,
plot_classic_pathway_map,
plot_default_pathway_graph,
plot_default_pathway_map,
Expand Down Expand Up @@ -288,15 +286,6 @@ def _plot_pathway_map(self, pathway_map: PathwayMap) -> None:
self.pathway_map_widget.draw()

def _plot_pathway_classic_map(self, pathway_map: PathwayMap) -> None:
plot_colours = PlotColours(
pathway_map_node_colours(pathway_map, self.colour_by_action_name),
pathway_map_node_styles(pathway_map),
pathway_map_edge_colours(pathway_map, self.colour_by_action_name),
pathway_map_edge_styles(pathway_map),
default_node_edge_colours(pathway_map),
default_label_colour(),
)

if pathway_map.nr_nodes() > 0:
pathway_map.assign_tipping_points(self.tipping_point_by_action, verify=True)

Expand All @@ -306,9 +295,11 @@ def _plot_pathway_classic_map(self, pathway_map: PathwayMap) -> None:
pathway_map.set_attribute("level_by_action", level_by_action)
pathway_map.set_attribute("colour_by_action_name", self.colour_by_action_name)

arguments = {"colour_by_action_name": self.colour_by_action_name}

self.pathway_map_classic_widget.axes.clear()
plot_classic_pathway_map(
self.pathway_map_classic_widget.axes, pathway_map, plot_colours=plot_colours
self.pathway_map_classic_widget.axes, pathway_map, arguments=arguments
)
self.pathway_map_classic_widget.draw()

Expand Down
Loading

0 comments on commit 5c8e94e

Please sign in to comment.