Create Interval Notation in Julia?

Hi all,

I wonder about creating interval notation using Intervals package, if there is any package that is able do tell me.

I try it this way:

using Plots, LaTeXStrings, Intervals

a = Interval{Closed, Closed}(1, 10)

plot(a)

But it returns unsuccessfully:
Cannot convert Interval{Int64, Closed, Closed} to series data for plotting

The goal is to create a simple interval notation for open and closed set / interval like this:

index

You could write your one latex recipe for Latexify.jl , see
https://korsbo.github.io/Latexify.jl/stable/tutorials/recipes/

For the Interval Notation it could be something like

@latexrecipe function f(x::Interval)
       return Expr(:latexifymerge, 
                    x.first in x ? "[" : "(", 
                    x.first, ",", 
                    x.last, 
                    x.last in x ? "]" : ")")
end

I’m not sure if you also wanted to generate the graphs, but for that you could of course also just use Latex and Latexify…

2 Likes

I manage to do it with lots of tricks:

using Plots, LaTeXStrings, Plots.PlotMeasures

plot([0.5,1],[0,0],arrow=true,color=:black,linewidth=2, xticks=false, yticks=false,
     showaxis=false, label="", bottom_margin = 10mm,)

annotate!([(0.65,0, (L"|", 14, :black))])
annotate!([(0.85,0, (L")", 14, :black))])
annotate!([(0.65,-0.1, (L"0", 10, :black))])
annotate!([(0.85,-0.1, (L"3", 10, :black))])

Capture d’écran_2022-08-26_17-00-43

Another better version:

using Plots, LaTeXStrings, Plots.PlotMeasures

f(x) = 0.1
plot([0.5,1],[0,0],arrow=true,color=:black,linewidth=2, xticks=false, yticks=false,
     ylims=(0,1), showaxis=false, label="", bottom_margin = 10mm)
plot!(f,0.5,0.85, fill=(0, 0.25, :blue), label="")

annotate!([(0.65,0, (L"|", 14, :black))])
annotate!([(0.85,0, (L")", 14, :black))])
annotate!([(0.65,-0.1, (L"0", 10, :black))])
annotate!([(0.85,-0.1, (L"3", 10, :black))])