# How can I get a plot for y when I use ACME package

**URL:** https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996
**Category:** Modelling & Simulations
**Tags:** package
**Created:** [May 28, 2021, 2:10pm UTC](https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996 "2021-05-28T14:10:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)
#### Post date: [May 28, 2021, 2:10pm UTC](https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996/1 "2021-05-28T14:10:47Z")

</div>

Hello everyone,  
I am using an example of a ACME.jl package to use for my project in which I should simulate a RLC circuit in Julia, but I don’t know how can I plot y according to time.  
this is the code which I use from example to expand for my project  
([Getting Started · ACME.jl](https://juliahub.com/docs/ACME/59NoK/0.9.3/gettingstarted/#Getting-Started-1))

using ACME

circ = @circuit begin  
j\_in = voltagesource()  
r1 = resistor(1e3)  
c1 = capacitor(47e-9)  
d1 = diode(is=1e-15)  
d2 = diode(is=1.8e-15)  
j\_out = voltageprobe()  
j\_in[+] ⟷ r1[1]  
j\_in[-] ⟷ gnd  
r1[2] ⟷ c1[1] ⟷ d1[+] ⟷ d2[-] ⟷ j\_out[+]  
gnd ⟷ c1[2] ⟷ d1[-] ⟷ d2[+] ⟷ j\_out[-]  
end  
model = DiscreteModel(circ, 1/44100)  
y = run!(model, sin.(2π _1000/44100_ (0:44099)’))  
and this the output 🙂  
1×100 Array{Float64,2}:  
1.83357e-8 3.1622e-7 2.59861e-6 … 0.00465423 0.00459275 0.00453208  
so now my question is how can use above matrix as well as time to get a plot

---

<div class="post-metadata">

### Author: ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)
#### Post date: [May 29, 2021, 5:32pm UTC](https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996/2 "2021-05-29T17:32:32Z")

</div>

### First order analysis

Looking at the code, it appears like this ACME.jl simulation uses a constant time step of `Ts=1/44100`, and it is driven by a `1kHz` sinusoidal source.

### Clean up code a bit

To start off, I would slightly modify your inputs for readability purposes:

```julia-auto
fs = 44100 #Hz - should be integer value.
fsig = 1000 #Hz - pick integer value to ensure whole periods are simulated.
Tsim = 1 #sec - pick integer value to ensure whole periods of fsig are simulated.

Tsim = round(Int, Tsim) #Recommendation: always simulate for whole periods
Nsamples = round(Int, Tsim*fs) - 1 # "-1" generates "cleaner" fft() results
t = (0:Nsamples)'/fs

model = DiscreteModel(circ, 1/fs)
y = run!(model, sin.(2π*f .* t))

```

### Plotting

For your first run, I suggest using Plots.jl. It seems to be the most popular on this forum, so more people can help you. It also supports multiple backends, so you can just switch to a different one by adding a single command later on. Here is the plotting code:

```julia-auto
using Plots
plot(t', y')

```

_ **NOTE:** _ ACME.jl appears to use row vectors, whereas Plots.jl expects column vectors. That’s why you need to plot the transpose of t & y.

### Switching backend

To switch backends, you simply select the desired backend after importing Plots.jl:

```julia-auto
using Plots
inspectdr() #Select InspectDR backend instead of default (GR)
plot(t', y')

```

Other Plots.jl backends are listed here:  
 → [Backends · Plots](http://docs.juliaplots.org/latest/backends/)

But for interactive circuit analysis, I suggest you use try out my own InspectDR backend. It was designed with exploring simulation results in mind:

- Large datasets.
- Mostly for functions of 1 argument (ex: voltage vs time; gain vs frequency, …)
- Quickly pan/zoom using bindkeys/mouse bindings.
- …

InspectDR repo (with link to sample plots):  
 → [GitHub - ma-laforge/InspectDR.jl: Fast, interactive Julia/GTK+ plots (+Smith charts +Gtk widget +Cairo-only images)](https://github.com/ma-laforge/InspectDR.jl)

Listing of bindkeys:  
 → [InspectDR.jl/doc/input\_bindings.md at master · ma-laforge/InspectDR.jl · GitHub](https://github.com/ma-laforge/InspectDR.jl/blob/master/doc/input_bindings.md)

---

<div class="post-metadata">

### Author: ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)
#### Post date: [May 29, 2021, 6:03pm UTC](https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996/3 "2021-05-29T18:03:12Z")

</div>

Dear Friend.  
I really appreciate the time and energy you spent for writing and thinking about my problem.  
I will check it

---

<div class="post-metadata">

### Author: ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)
#### Post date: [May 29, 2021, 8:11pm UTC](https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996/4 "2021-05-29T20:11:35Z")

</div>

> [@MA\_Laforge](#):
>
> `plot(t', y')`

dear friend.  
I use the code for simulating as you mention but the result seems incorrect,

![error2](https://global.discourse-cdn.com/julialang/original/3X/d/b/dbe7d07888e1deaa1325056b58d36981560f58c7.png)

---

<div class="post-metadata">

### Author: ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)
#### Post date: [May 29, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996/5 "2021-05-29T23:37:05Z")

</div>

Well, since your original `y` array used to have values of at least 0.00465423, whereas the plot is limited to `|values| < 4e-11`, I must have made a small mistake with my code cleanup suggestion.

For one, I’ve noticed I made a copy error here:

```julia
y = run!(model, sin.(2π*f .* t))

```

I should have used `fsig` instead:

```julia
y = run!(model, sin.(2π*fsig .* t))

```

---

<div class="post-metadata">

### Author: ![sajad\_ghassemi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sajad_ghassemi/32/25241_2.png) [@sajad\_ghassemi](https://discourse.julialang.org/u/sajad_ghassemi)
#### Post date: [May 30, 2021, 5:21am UTC](https://discourse.julialang.org/t/how-can-i-get-a-plot-for-y-when-i-use-acme-package/61996/6 "2021-05-30T05:21:23Z")

</div>

> [@MA\_Laforge](#):
>
> `plot(t', y')`

Thanks a million it worked . first I realized f should be something else. but I changed it to fs.
