CairoMakie, LoadError: InexactError: Int64(2.5)

Hello, I have a question about this error. I am doing an exercise to graph the supply-demand function using CairoMakie. I had no problems to place the scene and the layout but to graph the first curve I get this error message and I don’t know how to solve it.

P_supply(Q) = (Q + 6) / 3
P_demand(Q) = (-Q + 32)/ 2

#Visualize curves
using CairoMakie

#Initialize empty scene and layaout

scene, layout = layoutscene(resolution = (325, 325))
scene

#Añadir los ejes
ax = layout[1, 1]= Axis(scene,
xlabel = "Cantidad", xlabelsize = 10, xticklabelsize = 9, xticksize = 3,
ylabel = "Precio", ylabelsize = 10, yticklabelsize = 9, yticksize = 3,
ytickformat = "\${:d}",
title = "Oferta y demanda"
)
scene

#set x-axis range
Q_range = 1:25

#Graficar la curva de oferta
lineobject1 = lines!(ax, Q_range, P_supply, linewidth = 1, color = :blue)
scene
ERROR: LoadError: InexactError: Int64(2.5)
Stacktrace:
  [1] Int64
    @ .\float.jl:723 [inlined]
  [2] Integer
    @ .\boot.jl:786 [inlined]
  [3] _toint
    @ C:\Users\Admin\.julia\packages\Formatting\BwWBf\src\fmtspec.jl:172 [inlined]
  [4] printfmt(io::IOBuffer, fs::Formatting.FormatSpec, x::Float64)
    @ Formatting C:\Users\Admin\.julia\packages\Formatting\BwWBf\src\fmtspec.jl:181
  [5] printfmt(io::IOBuffer, fe::Formatting.FormatExpr, args::Float64)
    @ Formatting C:\Users\Admin\.julia\packages\Formatting\BwWBf\src\formatexpr.jl:147
  [6] printfmt(io::IOBuffer, fe::String, args::Float64)
    @ Formatting C:\Users\Admin\.julia\packages\Formatting\BwWBf\src\formatexpr.jl:159
  [7] sprint(::Function, ::String, ::Vararg{Any, N} where N; context::Nothing, sizehint::Int64)
    @ Base .\strings\io.jl:105
  [8] sprint
    @ .\strings\io.jl:101 [inlined]
  [9] format
    @ C:\Users\Admin\.julia\packages\Formatting\BwWBf\src\formatexpr.jl:165 [inlined]
 [10] #192
    @ .\none:0 [inlined]
 [11] iterate
    @ .\generator.jl:47 [inlined]
 [12] collect(itr::Base.Generator{Vector{Float64}, AbstractPlotting.MakieLayout.var"#192#193"{String}})
    @ Base .\array.jl:678
 [13] get_ticklabels
    @ C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\lineaxis.jl:482 [inlined]
 [14] get_ticks
    @ C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\lineaxis.jl:422 [inlined]
 [15] (::AbstractPlotting.MakieLayout.var"#139#170")(::Tuple{Float32, Tuple{Float32, Float32}, Bool}, limits::Tuple{Float32, 
Float32}, ticks::LinearTicks, tickformat::String)
    @ AbstractPlotting.MakieLayout C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\lineaxis.jl:197     
 [16] (::Observables.MapUpdater{AbstractPlotting.MakieLayout.var"#139#170", Tuple{Vector{Float64}, Vector{String}}})(::Tuple{Float32, Tuple{Float32, Float32}, Bool}, ::Vararg{Any, N} where N)
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:331
 [17] (::Observables.OnUpdate{Observables.MapUpdater{AbstractPlotting.MakieLayout.var"#139#170", Tuple{Vector{Float64}, Vector{String}}}, Tuple{Observable{Tuple{Float32, Tuple{Float32, Float32}, Bool}}, Observable{Any}, Observable{Any}, Observable{Any}}})(#unused#::Tuple{Float32, Float32})
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:298
 [18] setindex!(observable::Observable{Any}, val::Tuple{Float32, Float32}; notify::Observables.var"#9#11")
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:205
 [19] setindex!
    @ C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:201 [inlined]
 [20] (::Observables.var"#3#4"{Any, Observable{Any}})(value::Tuple{Float32, Float32})
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:46
 [21] #invokelatest#2
    @ .\essentials.jl:708 [inlined]
 [22] invokelatest
    @ .\essentials.jl:706 [inlined]
 [23] setindex!(observable::Observable{Tuple{Float32, Float32}}, val::Tuple{Float32, Float32}; notify::Observables.var"#9#11")
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:207
 [24] setindex!
    @ C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:201 [inlined]
 [25] MapUpdater
    @ C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:331 [inlined]
 [26] (::Observables.OnUpdate{Observables.MapUpdater{typeof(AbstractPlotting.MakieLayout.ylimits), Tuple{Float32, Float32}}, 
Tuple{Observable{GeometryBasics.HyperRectangle{2, Float32}}}})(#unused#::GeometryBasics.HyperRectangle{2, Float32})
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:298
 [27] setindex!(observable::Observable{GeometryBasics.HyperRectangle{2, Float32}}, val::GeometryBasics.HyperRectangle{2, Float32}; notify::Observables.var"#9#11")
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:205
 [28] setindex!(observable::Observable{GeometryBasics.HyperRectangle{2, Float32}}, val::GeometryBasics.HyperRectangle{2, Float32})
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:201
 [29] adjustlimits!(la::Axis)
    @ AbstractPlotting.MakieLayout C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\layoutables\axis.jl:662
 [30] #222
    @ C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\layoutables\axis.jl:399 [inlined]
 [31] (::Observables.OnUpdate{AbstractPlotting.MakieLayout.var"#222#251"{Axis}, Tuple{Observable{GeometryBasics.HyperRectangle{2, Int64}}, Observable{Any}}})(#unused#::GeometryBasics.HyperRectangle{2, Float32})
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:298
 [32] setindex!(observable::Observable{Any}, val::GeometryBasics.HyperRectangle{2, Float32}; notify::Observables.var"#9#11")
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:205
 [33] setindex!(observable::Observable{Any}, val::GeometryBasics.HyperRectangle{2, Float32})
    @ Observables C:\Users\Admin\.julia\packages\Observables\Yf3xU\src\Observables.jl:201
 [34] reset_limits!(ax::Axis; xauto::Bool, yauto::Bool)
    @ AbstractPlotting.MakieLayout C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\layoutables\axis.jl:439
 [35] reset_limits!
    @ C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\layoutables\axis.jl:416 [inlined]
 [36] #plot!#253
    @ C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\layoutables\axis.jl:464 [inlined]
 [37] plot!
    @ C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\layoutables\axis.jl:458 [inlined]
 [38] #plot!#254
    @ C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\makielayout\layoutables\axis.jl:470 [inlined]
 [39] lines!(::Axis, ::Vararg{Any, N} where N; attributes::Base.Iterators.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:linewidth, :color), Tuple{Int64, Symbol}}})
    @ AbstractPlotting C:\Users\Admin\.julia\packages\AbstractPlotting\vYUxj\src\recipes.jl:16
 [40] top-level scope
    @ c:\Users\Admin\Documents\9\Residencias\Programas VS Code\Julia\Control prueba.jl:66
in expression starting at c:\Users\Admin\Documents\9\Residencias\Programas VS Code\Julia\Control prueba.jl:66

I can’t check right now (I’m on my phone), but I think this is the culprit. Your P_supply function returns a float, which can’t be formatted like an Int if it’s not exactly an Int. (i.e. no decimal places). Try :f or no explicit ytickformat instead.

2 Likes

Thank you very much, it worked changing :d to :f