Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix graph defaults, plotting graphs #1189

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"

[extensions]
CatalystBifurcationKitExtension = "BifurcationKit"
CatalystCairoMakieExtension = "CairoMakie"
CatalystGraphMakieExtension = ["GraphMakie", "NetworkLayout"]
CatalystGraphMakieExtension = ["GraphMakie", "NetworkLayout", "Makie"]
CatalystHomotopyContinuationExtension = "HomotopyContinuation"

[compat]
Expand All @@ -56,6 +57,7 @@ JumpProcesses = "9.13.2"
LaTeXStrings = "1.3.0"
Latexify = "0.16.6"
MacroTools = "0.5.5"
Makie = "0.22.1"
ModelingToolkit = "< 9.60"
NetworkLayout = "0.4.7"
Parameters = "0.12"
Expand Down
14 changes: 7 additions & 7 deletions docs/src/model_creation/model_visualisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,34 @@ In this section we demonstrate some of the ways that plot objects can be manipul
f, ax, p = plot_complexes(brusselator, show_rate_labels = true)
```

It seems like a bit of the top node is cut off. Let's hide the tick marks and grid and increase the top and bottom margins by increasing `yautolimitmargin`.
It seems like a bit of the top node is cut off. Let's increase the top and bottom margins by increasing `yautolimitmargin`.
```@example visualisation_graphs
hidedecorations!(ax)
ax.yautolimitmargin = (0.1, 0.1) # defaults to (0.05, 0.05)
ax.yautolimitmargin = (0.3, 0.3) # defaults to (0.15, 0.15)
ax.aspect = DataAspect()
f
```

There are many keyword arguments that can be passed to `plot_network` or `plot_complexes` to change the look of the graph (which get passed to the `graphplot` Makie recipe). Let's change the color of the nodes and make the inner labels a bit smaller. As before, we hide the tick marks and grid. Let's also give the plot a title.
There are many keyword arguments that can be passed to `plot_network` or `plot_complexes` to change the look of the graph (which get passed to the `graphplot` Makie recipe). Let's change the color of the nodes and make the inner labels a bit smaller. Let's also give the plot a title.
```@example visualisation_graphs
f, ax, p = plot_complexes(brusselator, show_rate_labels = true, node_color = :yellow, ilabels_fontsize = 10)
hidedecorations!(ax)
ax.yautolimitmargin = (0.1, 0.1) # defaults to (0.05, 0.05)
ax.aspect = DataAspect()
ax.title = "Brusselator"
f
```

Most of the kwargs that modify the nodes or edges will also accept a vector with the same length as the number of nodes or edges, respectively. See [here](https://graph.makie.org/stable/#The-graphplot-Recipe) for a full list of keyword arguments to `graph_plot`. Note that `plot_complexes` and `plot_network` default to `layout = Stress()` rather than `layout = Spring()`, since `Stress()` is better at generating plots with fewer edge crossings. More layout options and customizations (such as pinning nodes to certain positions) can be found in the [`NetworkLayout` documentation](https://juliagraphs.org/NetworkLayout.jl/stable/).

Once a graph is already created we can also change the keyword arguments by modifying the fields of the `Plot` object `p`.
```@example visualisation_graphs
p.node_color = :orange
f
```

Custom node positions can also be given, if the automatic layout is unsatisfactory.
```@example visualisation_graphs
fixedlayout = [(0,0), (1,0), (0,1), (1,1), (2,0)]
p.layout = fixedlayout
autolimits!(ax)
f
```

Makie graph plots can be made to be interactive, allowing one to drag nodes and edges. To do this, we retrieve the axis from the GraphMakie plot, and then register the interactions. **Note that this can only be done if `GLMakie` is the installed Makie backend. See the [GraphMakie docs](https://graph.makie.org/stable/#Predefined-Interactions) for more information about the types of interactions one can register.** Below is a non-interactive code example that shows how to do this:
Expand Down
2 changes: 1 addition & 1 deletion ext/CatalystGraphMakieExtension.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module CatalystGraphMakieExtension

# Fetch packages.
using Catalyst, GraphMakie, Graphs, Symbolics, SparseArrays, NetworkLayout
using Catalyst, GraphMakie, Graphs, Symbolics, SparseArrays, NetworkLayout, Makie
using Symbolics: get_variables!
import Catalyst: species_reaction_graph, incidencematgraph, lattice_plot, lattice_animation

Expand Down
9 changes: 8 additions & 1 deletion ext/CatalystGraphMakieExtension/rn_graph_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ function Catalyst.plot_network(rn::ReactionSystem; kwargs...)

f.axis.xautolimitmargin = (0.15, 0.15)
f.axis.yautolimitmargin = (0.15, 0.15)
hidedecorations!(f.axis)
hidespines!(f.axis)
f.axis.aspect = DataAspect()

f
end
Expand Down Expand Up @@ -260,9 +263,13 @@ function Catalyst.plot_complexes(rn::ReactionSystem; show_rate_labels = false, k
curve_distance = gen_distances(cg),
kwargs...
)

f.axis.xautolimitmargin = (0.15, 0.15)
f.axis.yautolimitmargin = (0.15, 0.15)

hidedecorations!(f.axis)
hidespines!(f.axis)
f.axis.aspect = DataAspect()

f
end

Expand Down