How to plot y axis in log form, with differential equations?

Hello,

I would like advice on how to plot the results of differential equations in log format. I have searched the forums and the Plot.jl manual but cannot find an example.

I would like to plot the y-axis in log format but do not know how to do this. I just know I need to use yaxis=:log10 somehow.

What the y-axis represents is biomass, and I would like to transform the data to a log(biomass+1) scale. The +1 is to avoid error in case I have any zeros.

When I try:

plot(sol, tspan=(0.0,5000.0)), title = "Change in biomass", yaxis= :log10(Biomass + 1), xlabel = "Time" ,ylabel = "Biomass", lw=0.3)

Which generates

MethodError: no method matching +(::Array{Float64,1}, ::Int64)
Closest candidates are:
  +(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:502
  +(!Matched::Complex{Bool}, ::Real) at complex.jl:292
  +(!Matched::Missing, ::Number) at missing.jl:97
  ...
top-level scope at none:0

Or when I try

plot(sol, tspan=(0.0,5000.0)), title = "Change in biomass", yaxis= :log10(+1), xlabel = "Time" ,ylabel = "Biomass", lw=0.3)

Generates

MethodError: objects of type Symbol are not callable top-level scope at none:0

Any advice?

2 Likes
f(x,y) = (x,y+1)
plot(sol, vars = (f,0,1), tspan=(0.0,5000.0)), title = "Change in biomass", yaxis= :log10, xlabel = "Time" ,ylabel = "Biomass", lw=0.3)

Does this mean I do not need to add 1 to prevent errors if I have some 0 values in the biomass?

It’s using the shifted biomass.

Using yaxis= :log10 works with a smaller amount of biomasses (6 in this case) but generates an error when I try to plot it for 42.

Julia Client – Internal Error

ArgumentError: At least one finite value must be provided to formatter.
showoff(::Array{Float64,1}, ::Symbol) at Showoff.jl:105
optimal_ticks_and_labels(::Plots.Subplot{Plots.GRBackend}, ::Plots.Axis, ::Nothing) at axes.jl:215
optimal_ticks_and_labels at axes.jl:156 [inlined]
get_ticks(::Plots.Subplot{Plots.GRBackend}, ::Plots.Axis) at axes.jl:264
axis_drawing_info(::Plots.Subplot{Plots.GRBackend}) at axes.jl:620
_update_min_padding!(::Plots.Subplot{Plots.GRBackend}) at gr.jl:794
iterate at generator.jl:47 [inlined]
_collect(::Array{AbstractLayout,2}, ::Base.Generator{Array{AbstractLayout,2},typeof(Plots._update_min_padding!)}, ::Base.EltypeUnknown, ::Base.HasShape{2}) at array.jl:619
collect_similar at array.jl:548 [inlined]
map at abstractarray.jl:2018 [inlined]
_update_min_padding!(::Plots.GridLayout) at layouts.jl:310
prepare_output(::Plots.Plot{Plots.GRBackend}) at plot.jl:261
showjuno(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/svg+xml")}, ::Plots.Plot{Plots.GRBackend}) at output.jl:243
show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/svg+xml")}, ::Plots.Plot{Plots.GRBackend}) at output.jl:195
__binrepr at multimedia.jl:129 [inlined]
_textrepr at multimedia.jl:119 [inlined]
#stringmime#6 at Base64.jl:38 [inlined]
(::getfield(Base64, Symbol("#kw##stringmime")))(::NamedTuple{(:context,),Tuple{IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}}}, ::typeof(Base64.stringmime), ::MIME{Symbol("image/svg+xml")}, ::Plots.Plot{Plots.GRBackend}) at none:0
#stringmime#7(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Function, ::String, ::Plots.Plot{Plots.GRBackend}) at Base64.jl:39
#stringmime at none:0 [inlined]
displayinplotpane(::Plots.Plot{Plots.GRBackend}) at showdisplay.jl:55
displayandrender(::Plots.Plot{Plots.GRBackend}) at showdisplay.jl:115
(::getfield(Atom, Symbol("##117#122")){String})() at eval.jl:102
macro expansion at essentials.jl:742 [inlined]
(::getfield(Atom, Symbol("##113#118")))(::Dict{String,Any}) at eval.jl:86
handlemsg(::Dict{String,Any}, ::Dict{String,Any}) at comm.jl:164
(::getfield(Atom, Symbol("##19#21")){Array{Any,1}})() at task.jl:259

Does anyone know what is happening?

are you not using the vars as I showed?

If I use the vars you showed, something strange happens

In the plot function, we need to include yaxis = log10.(Biomass .+ 1) to get the log form with 1 added to prevent errors from 0 values.