# Plotting with break in axis using Plot.jl

**URL:** https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140
**Category:** New to Julia
**Tags:** question, plotting, plots
**Created:** [June 24, 2024, 12:39pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140 "2024-06-24T12:39:54Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)
#### Post date: [June 24, 2024, 12:39pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140/1 "2024-06-24T12:39:54Z")

</div>

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](https://global.discourse-cdn.com/julialang/original/3X/e/9/e96b832607378f350eb935e85af12b85d66e35bd.png)

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 🙂

---

<div class="post-metadata">

### Author: ![oOosys](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ooosys/32/209566_2.png) [@oOosys](https://discourse.julialang.org/u/oOosys)
#### Post date: [June 24, 2024, 1:50pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140/2 "2024-06-24T13:50:52Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)
#### Post date: [June 24, 2024, 1:58pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140/3 "2024-06-24T13:58:52Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [June 24, 2024, 2:05pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140/4 "2024-06-24T14:05:48Z")

</div>

Linking related [Plots.jl’s thread](https://discourse.julialang.org/t/plots-gr-axis-break/59322), with code example for breakplots.

---

<div class="post-metadata">

### Author: ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)
#### Post date: [June 24, 2024, 2:09pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140/5 "2024-06-24T14:09:04Z")

</div>

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:

 ![demochart](https://global.discourse-cdn.com/julialang/original/3X/c/c/cc234720b4b2bd6fb9624bcadf5d65ee06b83dd9.png)

---

<div class="post-metadata">

### Author: ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)
#### Post date: [June 24, 2024, 2:19pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140/6 "2024-06-24T14:19:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)
#### Post date: [June 24, 2024, 3:11pm UTC](https://discourse.julialang.org/t/plotting-with-break-in-axis-using-plot-jl/116140/7 "2024-06-24T15:11:44Z")

</div>

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

```julia
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

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/0/d05fb89d31f59d24f9ef9855799c68c9d56e58d2.png)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/5/05c7da72cdd1f16e35b905ec216621f44eb4a2da.png)
