Skip to content

Commit 0667614

Browse files
committed
updating docs
1 parent d4e08c2 commit 0667614

File tree

3 files changed

+65
-14
lines changed

3 files changed

+65
-14
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ JumpProcesses = "9.13.2"
5858
LaTeXStrings = "1.3.0"
5959
Latexify = "0.16.5"
6060
MacroTools = "0.5.5"
61-
ModelingToolkit = "9.32"
61+
ModelingToolkit = "< 9.60"
6262
NetworkLayout = "0.4.7"
6363
Parameters = "0.12"
6464
Reexport = "0.2, 1.0"
6565
Requires = "1.0"
6666
RuntimeGeneratedFunctions = "0.5.12"
67-
SciMLBase = "2.57.2"
67+
SciMLBase = "< 2.66.1"
6868
Setfield = "1"
6969
# StructuralIdentifiability = "0.5.8"
7070
SymbolicUtils = "2.1.2, 3.3.0"

docs/src/model_creation/model_visualisation.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,44 @@ Here, reaction complexes are displayed as blue nodes, and reactions between comp
8181
plot_complexes(brusselator, show_rate_labels = true)
8282
```
8383

84-
Makie graphs 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:
84+
## Customizing Plots
85+
In this section we demonstrate some of the ways that plot objects can be manipulated to give nicer images. Let's start with our brusselator plot once again. Note that the `plot` function returns three objects: the `Figure`, the `Axis`, and the `Plot`, which can each be customized independently. See the general [Makie documentation](https://docs.makie.org/stable/) for more information.
86+
87+
```@example visualisation_graphs
88+
f, ax, p = plot_complexes(brusselator, show_rate_labels = true)
89+
```
90+
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`.
92+
```@example visualisation_graphs
93+
hidedecorations!(ax)
94+
ax.yautolimitmargin = (0.1, 0.1) # defaults to (0.05, 0.05)
95+
ax.aspect = DataAspect()
96+
```
97+
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.
99+
```@example visualisation_graphs
100+
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()
104+
ax.title = "Brusselator"
105+
```
106+
107+
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/).
108+
109+
Once a graph is already created we can also change the keyword arguments by modifying the fields of the `Plot` object `p`.
110+
```@example visualisation_graphs
111+
p.node_color = :orange
112+
```
113+
114+
Custom node positions can also be given, if the automatic layout is unsatisfactory.
115+
```@example visualisation_graphs
116+
fixedlayout = [(0,0), (1,0), (0,1), (1,1), (2,0)]
117+
p.layout = fixedlayout
118+
autolimits!(ax)
119+
```
120+
121+
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:
85122

86123
```julia
87124
using GLMakie
@@ -96,3 +133,8 @@ The equivalent of `show` for Makie plots is the `display` function.
96133
f = plot_network(brusselator)
97134
display(f)
98135
```
136+
137+
Once you are happy with the graph plot, you can save it using the `save` function.
138+
```julia
139+
save("fig.png", f)
140+
```

ext/CatalystGraphMakieExtension/rn_graph_plot.jl

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function Catalyst.plot_network(rn::ReactionSystem; kwargs...)
193193
layout = if !haskey(kwargs, :layout)
194194
Stress()
195195
end
196-
graphplot(srg;
196+
f, ax, p = graphplot(srg;
197197
layout,
198198
edge_color = edgecolors,
199199
elabels = edgelabels,
@@ -206,21 +206,26 @@ function Catalyst.plot_network(rn::ReactionSystem; kwargs...)
206206
curve_distance = gen_distances(srg),
207207
kwargs...
208208
)
209+
210+
ax.xautolimitmargin = (0.15, 0.15)
211+
ax.yautolimitmargin = (0.15, 0.15)
212+
213+
f, ax, p
209214
end
210215

211216
"""
212217
plot_complexes(rn::ReactionSystem; show_rate_labels = false, kwargs...)
213218
214-
Creates a GraphMakie plot of the [`ReactionComplex`](@ref)s in `rn`. Reactions
215-
correspond to arrows and reaction complexes to blue circles.
219+
Creates a GraphMakie plot of the [`ReactionComplex`](@ref)s in `rn`. Reactions
220+
correspond to arrows and reaction complexes to blue circles.
216221
217-
Notes:
218-
- Black arrows from complexes to complexes indicate reactions whose rate is a
219-
parameter or a `Number`. i.e. `k, A --> B`.
220-
- Red arrows from complexes to complexes indicate reactions whose rate constants
221-
depends on species. i.e. `k*C, A --> B` for `C` a species.
222-
- The `show_rate_labels` keyword, if set to `true`, will annotate each edge
223-
with the rate constant for the reaction.
222+
Notes:
223+
- Black arrows from complexes to complexes indicate reactions whose rate is a
224+
parameter or a `Number`. i.e. `k, A --> B`.
225+
- Red arrows from complexes to complexes indicate reactions whose rate constants
226+
depends on species. i.e. `k*C, A --> B` for `C` a species.
227+
- The `show_rate_labels` keyword, if set to `true`, will annotate each edge
228+
with the rate constant for the reaction.
224229
225230
For a list of accepted keyword arguments to the graph plot, please see the [GraphMakie documentation](https://graph.makie.org/stable/#The-graphplot-Recipe).
226231
"""
@@ -243,7 +248,7 @@ function Catalyst.plot_complexes(rn::ReactionSystem; show_rate_labels = false, k
243248
layout = if !haskey(kwargs, :layout)
244249
Stress()
245250
end
246-
graphplot(cg;
251+
f, ax, p = graphplot(cg;
247252
layout,
248253
edge_color = edgecolors[rxorder],
249254
elabels = show_rate_labels ? edgelabels[rxorder] : [],
@@ -255,6 +260,10 @@ function Catalyst.plot_complexes(rn::ReactionSystem; show_rate_labels = false, k
255260
curve_distance = gen_distances(cg),
256261
kwargs...
257262
)
263+
ax.xautolimitmargin = (0.15, 0.15)
264+
ax.yautolimitmargin = (0.15, 0.15)
265+
266+
f, ax, p
258267
end
259268

260269
function complexelem_tostr(e::Catalyst.ReactionComplexElement, specstrs)

0 commit comments

Comments
 (0)