Skip to content

Commit 40953ac

Browse files
authored
Merge pull request #1189 from vyudu/fix_graph_defaults
Fix graph defaults, plotting graphs
2 parents 4d0e7c2 + 4791d58 commit 40953ac

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
3232
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3333
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
3434
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
35+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
3536
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
3637

3738
[extensions]
3839
CatalystBifurcationKitExtension = "BifurcationKit"
3940
CatalystCairoMakieExtension = "CairoMakie"
40-
CatalystGraphMakieExtension = ["GraphMakie", "NetworkLayout"]
41+
CatalystGraphMakieExtension = ["GraphMakie", "NetworkLayout", "Makie"]
4142
CatalystHomotopyContinuationExtension = "HomotopyContinuation"
4243

4344
[compat]
@@ -56,6 +57,7 @@ JumpProcesses = "9.13.2"
5657
LaTeXStrings = "1.3.0"
5758
Latexify = "0.16.6"
5859
MacroTools = "0.5.5"
60+
Makie = "0.22.1"
5961
ModelingToolkit = "< 9.60"
6062
NetworkLayout = "0.4.7"
6163
Parameters = "0.12"

docs/src/model_creation/model_visualisation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,34 @@ In this section we demonstrate some of the ways that plot objects can be manipul
8888
f, ax, p = plot_complexes(brusselator, show_rate_labels = true)
8989
```
9090

91-
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`.
91+
It seems like a bit of the top node is cut off. Let's increase the top and bottom margins by increasing `yautolimitmargin`.
9292
```@example visualisation_graphs
93-
hidedecorations!(ax)
94-
ax.yautolimitmargin = (0.1, 0.1) # defaults to (0.05, 0.05)
93+
ax.yautolimitmargin = (0.3, 0.3) # defaults to (0.15, 0.15)
9594
ax.aspect = DataAspect()
95+
f
9696
```
9797

98-
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.
98+
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.
9999
```@example visualisation_graphs
100100
f, ax, p = plot_complexes(brusselator, show_rate_labels = true, node_color = :yellow, ilabels_fontsize = 10)
101-
hidedecorations!(ax)
102-
ax.yautolimitmargin = (0.1, 0.1) # defaults to (0.05, 0.05)
103-
ax.aspect = DataAspect()
104101
ax.title = "Brusselator"
102+
f
105103
```
106104

107105
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/).
108106

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

114113
Custom node positions can also be given, if the automatic layout is unsatisfactory.
115114
```@example visualisation_graphs
116115
fixedlayout = [(0,0), (1,0), (0,1), (1,1), (2,0)]
117116
p.layout = fixedlayout
118117
autolimits!(ax)
118+
f
119119
```
120120

121121
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:

ext/CatalystGraphMakieExtension.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module CatalystGraphMakieExtension
22

33
# Fetch packages.
4-
using Catalyst, GraphMakie, Graphs, Symbolics, SparseArrays, NetworkLayout
4+
using Catalyst, GraphMakie, Graphs, Symbolics, SparseArrays, NetworkLayout, Makie
55
using Symbolics: get_variables!
66
import Catalyst: species_reaction_graph, incidencematgraph, lattice_plot, lattice_animation
77

ext/CatalystGraphMakieExtension/rn_graph_plot.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ function Catalyst.plot_network(rn::ReactionSystem; kwargs...)
209209

210210
f.axis.xautolimitmargin = (0.15, 0.15)
211211
f.axis.yautolimitmargin = (0.15, 0.15)
212+
hidedecorations!(f.axis)
213+
hidespines!(f.axis)
214+
f.axis.aspect = DataAspect()
212215

213216
f
214217
end
@@ -260,9 +263,13 @@ function Catalyst.plot_complexes(rn::ReactionSystem; show_rate_labels = false, k
260263
curve_distance = gen_distances(cg),
261264
kwargs...
262265
)
266+
263267
f.axis.xautolimitmargin = (0.15, 0.15)
264268
f.axis.yautolimitmargin = (0.15, 0.15)
265-
269+
hidedecorations!(f.axis)
270+
hidespines!(f.axis)
271+
f.axis.aspect = DataAspect()
272+
266273
f
267274
end
268275

0 commit comments

Comments
 (0)