Plotting with break in axis using Plot.jl

I have data with has same y-axis range but for x-axis it has two different set of datapoints at far locations. Now plan is to plot them together with a break in x-axis.

I was trying initially with just directly using Plot.jl with led to connection of both sets with line which looks weird.

image

I would want to plot this without connecting line individually and introducing a break for data not present in between.

It will be helpful if someone can suggest if there is already an attribute for this in Plots.jl.

Thank you :slight_smile:

If you provide the code for the diagram in the image it would be sure easier for respondents to provide answers backed up with adjusted code.
By the way: why not switch the axes for the plot taking advantage of same y-range displaying it at the x-axis?

Divide the points into two sets, and plot them separately. Along the lines of

x1, y1 = ...
x2, y2 = ...
plot(x1, y1)
plot!(x2, y2)

Linking related Plots.jl’s thread, with code example for breakplots.

Maybe it is even better to add an inset graph of the unbroken x-axis with rectangles showing the plot area of the two different larger charts.

Something like:

1 Like

I don’t know if this is easy, but you could try subtracting 400 (or something) from x in the second set of data. Then, plot both on the same x-axis but manually place and label the ticks on the x-axis.

Crude, but it works.
Using Makie not Plots, I’m afraid, but presumably same idea applies!

using PDFmerger
import CairoMakie as Mke

let
    x1=Int[]
    x2=Int[]
    y=Int[]
        for i=1:10
        push!(x1, i)
        push!(x2, i + 500)
        push!(y, i)
        end

    fig, ax, plot = Mke.scatterlines(x1, y)
    Mke.scatterlines!(x2, y)
    Mke.save("testplot.pdf", fig)
    for i in eachindex(x2)
        if x2[i]>200
            x2[i] -= 450
        end
    end
    fig2, ax2, plot2 = Mke.scatterlines(x1, y)
    ax2.xticks = (0:10:60, ["0", "10", "20", "//", "490", "500", "510"])
    Mke.scatterlines!(x2, y)
    Mke.save("tmp.pdf", fig2)
    append_pdf!("testplot.pdf", "tmp.pdf", cleanup=true)


end