Skip to content

Commit 759d808

Browse files
Merge pull request #321 from SciML/rebuild/85953a96
Rebuild introduction/05-formatting_plots.jmd
2 parents 64cbe4c + d92adec commit 759d808

16 files changed

+66
-44
lines changed

html/introduction/05-formatting_plots.html

Lines changed: 26 additions & 26 deletions
Large diffs are not rendered by default.

markdown/introduction/05-formatting_plots.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ title: "Formatting Plots"
44
---
55

66

7-
Since the plotting functionality is implemented as a recipe to Plots.jl, [all of the options open to Plots.jl can be used in our plots](https://juliaplots.github.io/supported/). In addition, there are special features specifically for [differential equation plots](https://docs.juliadiffeq.org/dev/basics/plot/). This tutorial will teach some of the most commonly used options. Let's first get the solution to some ODE. Here I will use one of the Lorenz ordinary differential equation. As with all commands in DifferentialEquations.jl, I got a plot of the solution by calling `solve` on the problem, and `plot` on the solution:
7+
Since the plotting functionality is implemented as a recipe to Plots.jl, [all of the options open to Plots.jl can be used in our plots](https://juliaplots.github.io/supported/). In addition, there are special features specifically for [differential equation plots](https://docs.sciml.ai/dev/basics/plot/). This tutorial will teach some of the most commonly used options. Let's first get the solution to some ODE. Here I will use one of the Lorenz ordinary differential equation. As with all commands in DifferentialEquations.jl, I got a plot of the solution by calling `solve` on the problem, and `plot` on the solution:
88

99
````julia
10+
1011
using DifferentialEquations, Plots, ParameterizedFunctions
1112
gr()
1213
lorenz = @ode_def Lorenz begin
@@ -25,7 +26,7 @@ sol = solve(prob)
2526

2627
````
2728
retcode: Success
28-
Interpolation: Automatic order switching interpolation
29+
Interpolation: automatic order switching interpolation
2930
t: 1341-element Array{Float64,1}:
3031
0.0
3132
0.0354861341350177
@@ -73,6 +74,7 @@ u: 1341-element Array{Array{Float64,1},1}:
7374

7475

7576
````julia
77+
7678
plot(sol)
7779
````
7880

@@ -81,9 +83,10 @@ plot(sol)
8183

8284

8385

84-
Now let's change it to a phase plot. As discussed in the [plot functions page](https://docs.juliadiffeq.org/dev/basics/plot/), we can use the `vars` command to choose the variables to plot. Let's plot variable `x` vs variable `y` vs variable `z`:
86+
Now let's change it to a phase plot. As discussed in the [plot functions page](https://docs.sciml.ai/dev/basics/plot/), we can use the `vars` command to choose the variables to plot. Let's plot variable `x` vs variable `y` vs variable `z`:
8587

8688
````julia
89+
8790
plot(sol,vars=(1, 2, 3))
8891
````
8992

@@ -95,6 +98,7 @@ plot(sol,vars=(1, 2, 3))
9598
We can also choose to plot the timeseries for a single variable:
9699

97100
````julia
101+
98102
plot(sol,vars=[:x])
99103
````
100104

@@ -106,6 +110,7 @@ plot(sol,vars=[:x])
106110
Notice that we were able to use the variable names because we had defined the problem with the macro. But in general, we can use the indices. The previous plots would be:
107111

108112
````julia
113+
109114
plot(sol,vars=(1,2,3))
110115
plot(sol,vars=[1])
111116
````
@@ -118,6 +123,7 @@ plot(sol,vars=[1])
118123
Common options are to add titles, axis, and labels. For example:
119124

120125
````julia
126+
121127
plot(sol,linewidth=5,title="Solution to the linear ODE with a thick line",
122128
xaxis="Time (t)",yaxis="u(t) (in mm)",label=["X","Y","Z"])
123129
````
@@ -130,6 +136,7 @@ xaxis="Time (t)",yaxis="u(t) (in mm)",label=["X","Y","Z"])
130136
Notice that series recipes apply to the solution type as well. For example, we can use a scatter plot on the timeseries:
131137

132138
````julia
139+
133140
scatter(sol,vars=[:x])
134141
````
135142

@@ -141,6 +148,7 @@ scatter(sol,vars=[:x])
141148
This shows that the recipe is using the interpolation to smooth the plot. It becomes abundantly clear when we turn it off using `denseplot=false`:
142149

143150
````julia
151+
144152
plot(sol,vars=(1,2,3),denseplot=false)
145153
````
146154

@@ -152,6 +160,7 @@ plot(sol,vars=(1,2,3),denseplot=false)
152160
When this is done, only the values the timestep hits are plotted. Using the interpolation usually results in a much nicer looking plot so it's recommended, and since the interpolations have similar orders to the numerical methods, their results are trustworthy on the full interval. We can control the number of points used in the interpolation's plot using the `plotdensity` command:
153161

154162
````julia
163+
155164
plot(sol,vars=(1,2,3),plotdensity=100)
156165
````
157166

@@ -163,6 +172,7 @@ plot(sol,vars=(1,2,3),plotdensity=100)
163172
That's plotting the entire solution using 100 points spaced evenly in time.
164173

165174
````julia
175+
166176
plot(sol,vars=(1,2,3),plotdensity=10000)
167177
````
168178

@@ -176,6 +186,7 @@ That's more like it! By default it uses `100*length(sol)`, where the length is t
176186
Lastly notice that we can compose plots. Let's show where the 100 points are using a scatter plot:
177187

178188
````julia
189+
179190
plot(sol,vars=(1,2,3))
180191
scatter!(sol,vars=(1,2,3),plotdensity=100)
181192
````
@@ -188,6 +199,7 @@ scatter!(sol,vars=(1,2,3),plotdensity=100)
188199
We can instead work with an explicit plot object. This form can be better for building a complex plot in a loop.
189200

190201
````julia
202+
191203
p = plot(sol,vars=(1,2,3))
192204
scatter!(p,sol,vars=(1,2,3),plotdensity=100)
193205
title!("I added a title")
@@ -203,12 +215,13 @@ You can do all sorts of things. Have fun!
203215

204216
## Appendix
205217

206-
This tutorial is part of the DiffEqTutorials.jl repository, found at: <https://github.com/JuliaDiffEq/DiffEqTutorials.jl>
218+
This tutorial is part of the SciMLTutorials.jl repository, found at: <https://github.com/SciML/SciMLTutorials.jl>.
219+
For more information on doing scientific machine learning (SciML) with open source software, check out <https://sciml.ai/>.
207220

208221
To locally run this tutorial, do the following commands:
209222
```
210-
using DiffEqTutorials
211-
DiffEqTutorials.weave_file("introduction","05-formatting_plots.jmd")
223+
using SciMLTutorials
224+
SciMLTutorials.weave_file("introduction","05-formatting_plots.jmd")
212225
```
213226

214227
Computer Information:
@@ -222,10 +235,10 @@ Platform Info:
222235
LIBM: libopenlibm
223236
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
224237
Environment:
238+
JULIA_LOAD_PATH = /builds/JuliaGPU/DiffEqTutorials.jl:
225239
JULIA_DEPOT_PATH = /builds/JuliaGPU/DiffEqTutorials.jl/.julia
226-
JULIA_CUDA_MEMORY_LIMIT = 536870912
227-
JULIA_PROJECT = @.
228-
JULIA_NUM_THREADS = 4
240+
JULIA_CUDA_MEMORY_LIMIT = 2147483648
241+
JULIA_NUM_THREADS = 8
229242
230243
```
231244

@@ -234,10 +247,10 @@ Package Information:
234247
```
235248
Status `/builds/JuliaGPU/DiffEqTutorials.jl/tutorials/introduction/Project.toml`
236249
[6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf] BenchmarkTools 0.5.0
237-
[0c46a032-eb83-5123-abaf-570d42b7fbaa] DifferentialEquations 6.14.0
238-
[65888b18-ceab-5e60-b2b9-181511a3b968] ParameterizedFunctions 5.3.0
239-
[91a5bcdd-55d7-5caf-9e0b-520d859cae80] Plots 1.4.3
240-
[90137ffa-7385-5640-81b9-e52037218182] StaticArrays 0.12.3
241-
[c3572dad-4567-51f8-b174-8c6c989267f4] Sundials 4.2.3
250+
[0c46a032-eb83-5123-abaf-570d42b7fbaa] DifferentialEquations 6.15.0
251+
[65888b18-ceab-5e60-b2b9-181511a3b968] ParameterizedFunctions 5.6.0
252+
[91a5bcdd-55d7-5caf-9e0b-520d859cae80] Plots 1.6.3
253+
[90137ffa-7385-5640-81b9-e52037218182] StaticArrays 0.12.4
254+
[c3572dad-4567-51f8-b174-8c6c989267f4] Sundials 4.3.0
242255
[37e2e46d-f89d-539d-b4ee-838fcccc9c8e] LinearAlgebra
243256
```
131 Bytes
Loading
852 Bytes
Loading
711 Bytes
Loading
-314 Bytes
Loading
76 Bytes
Loading
932 Bytes
Loading
932 Bytes
Loading
-439 Bytes
Loading

0 commit comments

Comments
 (0)