You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: markdown/introduction/05-formatting_plots.md
+27-14Lines changed: 27 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,10 @@ title: "Formatting Plots"
4
4
---
5
5
6
6
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:
8
8
9
9
````julia
10
+
10
11
using DifferentialEquations, Plots, ParameterizedFunctions
11
12
gr()
12
13
lorenz =@ode_def Lorenz begin
@@ -25,7 +26,7 @@ sol = solve(prob)
25
26
26
27
````
27
28
retcode: Success
28
-
Interpolation: Automatic order switching interpolation
29
+
Interpolation: automatic order switching interpolation
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`:
85
87
86
88
````julia
89
+
87
90
plot(sol,vars=(1, 2, 3))
88
91
````
89
92
@@ -95,6 +98,7 @@ plot(sol,vars=(1, 2, 3))
95
98
We can also choose to plot the timeseries for a single variable:
96
99
97
100
````julia
101
+
98
102
plot(sol,vars=[:x])
99
103
````
100
104
@@ -106,6 +110,7 @@ plot(sol,vars=[:x])
106
110
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:
107
111
108
112
````julia
113
+
109
114
plot(sol,vars=(1,2,3))
110
115
plot(sol,vars=[1])
111
116
````
@@ -118,6 +123,7 @@ plot(sol,vars=[1])
118
123
Common options are to add titles, axis, and labels. For example:
119
124
120
125
````julia
126
+
121
127
plot(sol,linewidth=5,title="Solution to the linear ODE with a thick line",
122
128
xaxis="Time (t)",yaxis="u(t) (in mm)",label=["X","Y","Z"])
123
129
````
@@ -130,6 +136,7 @@ xaxis="Time (t)",yaxis="u(t) (in mm)",label=["X","Y","Z"])
130
136
Notice that series recipes apply to the solution type as well. For example, we can use a scatter plot on the timeseries:
131
137
132
138
````julia
139
+
133
140
scatter(sol,vars=[:x])
134
141
````
135
142
@@ -141,6 +148,7 @@ scatter(sol,vars=[:x])
141
148
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`:
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:
0 commit comments