Skip to content

Commit b895f4a

Browse files
authored
Add Makie recipes for all plots (#1018)
* add Makie extension * fixes * fix simresultplot * add docs * add angle unwrapping in nicholsplot * add mutating versions * Switch to CairoMakie in tests * handle imports nicer * improve test coverage slightly * add legend to step plot
1 parent 2c732aa commit b895f4a

File tree

7 files changed

+1041
-1
lines changed

7 files changed

+1041
-1
lines changed

docs/src/lib/plotting.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Pages = ["plotting.md"]
88
!!! note "Time-domain responses"
99
There are no special functions to plot time-domain results, such as step and impulse responses, instead, simply call `plot` on the result structure (`ControlSystemsBase.SimResult`) returned by [`lsim`](@ref), [`step`](@ref), [`impulse`](@ref) etc.
1010

11+
1112
# Plotting functions
1213

1314
```@autodocs
@@ -115,3 +116,49 @@ res = step(sysd, 5)
115116
plot(res, l=(:dash, 4))
116117
# plot!(stepinfo(step(sysd[1,1], 5))) # adds extra info to the plot
117118
```
119+
120+
121+
## Makie support
122+
!!! danger "Experimental"
123+
124+
The support for plotting with Makie is currently experimental and at any time subject to breaking changes or removal **not** respecting semantic versioning.
125+
126+
ControlSystemsBase provides experimental support for plotting with [Makie.jl](https://docs.makie.org/) through the `CSMakie` module. This support is loaded automatically when you load a Makie backend (GLMakie, CairoMakie, or WGLMakie).
127+
128+
### Usage
129+
130+
```julia
131+
using ControlSystemsBase, GLMakie # or CairoMakie, WGLMakie
132+
133+
# Create a system
134+
P = tf([1], [1, 2, 1])
135+
136+
# Use CSMakie plotting functions
137+
CSMakie.bodeplot(P)
138+
CSMakie.nyquistplot(P)
139+
CSMakie.pzmap(P)
140+
# ... and more
141+
142+
# Direct plotting of simulation results
143+
res = step(P, 10)
144+
plot(res) # Creates a figure with time-domain response
145+
146+
si = stepinfo(res)
147+
plot(si) # Visualizes step response characteristics
148+
```
149+
150+
### Available functions
151+
152+
The `CSMakie` module provides Makie implementations of the following plotting functions:
153+
154+
- `CSMakie.bodeplot` - Bode magnitude and phase plots
155+
- `CSMakie.nyquistplot` - Nyquist plots with optional M and Mt circles
156+
- `CSMakie.sigmaplot` - Singular value plots
157+
- `CSMakie.marginplot` - Gain and phase margin plots
158+
- `CSMakie.pzmap` - Pole-zero maps
159+
- `CSMakie.nicholsplot` - Nichols charts
160+
- `CSMakie.rgaplot` - Relative gain array plots
161+
- `CSMakie.rlocusplot` - Root locus plots
162+
- `CSMakie.leadlinkcurve` - Lead-link design curves
163+
164+
Additionally, `SimResult` and `StepInfo` types can be plotted directly using Makie's `plot` function.

lib/ControlSystemsBase/Project.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
2323
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
2424
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
2525
ImplicitDifferentiation = "57b37032-215b-411a-8a7c-41a003a55207"
26+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
2627

2728
[extensions]
2829
ControlSystemsBaseDSPExt = ["DSP"]
2930
ControlSystemsBaseImplicitDifferentiationExt = ["ImplicitDifferentiation", "ComponentArrays"]
31+
ControlSystemsBaseMakieExt = ["Makie"]
3032

3133
[compat]
3234
Aqua = "0.5"
@@ -37,6 +39,7 @@ Hungarian = "0.7.0"
3739
ImplicitDifferentiation = "0.7.2"
3840
LinearAlgebra = "<0.0.1, 1"
3941
MacroTools = "0.5"
42+
Makie = "0.24"
4043
MatrixEquations = "1, 2.1"
4144
MatrixPencils = "1.8.3"
4245
Polynomials = "3.0, 4.0"
@@ -50,17 +53,19 @@ julia = "1.6"
5053

5154
[extras]
5255
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
56+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
5357
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
5458
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
5559
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
5660
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
5761
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
5862
GenericSchur = "c145ed77-6b09-5dd9-b285-bf645a82121e"
5963
ImplicitDifferentiation = "57b37032-215b-411a-8a7c-41a003a55207"
64+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
6065
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
6166
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
6267
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
6368
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6469

6570
[targets]
66-
test = ["Test", "Aqua", "ComponentArrays", "Documenter", "DSP", "FiniteDifferences", "ImplicitDifferentiation", "GenericSchur", "GR", "Plots", "SparseArrays", "StaticArrays"]
71+
test = ["Test", "Aqua", "ComponentArrays", "Documenter", "DSP", "FiniteDifferences", "ImplicitDifferentiation", "Makie", "CairoMakie", "GenericSchur", "GR", "Plots", "SparseArrays", "StaticArrays"]

0 commit comments

Comments
 (0)