# Plot multiple lines with different ranges in same plot

**URL:** <https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [March 2, 2021, 5:51am UTC](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304 "2021-03-02T05:51:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hannah\_Rocio\_Santa\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hannah_rocio_santa_c/32/21913_2.png) [@Hannah\_Rocio\_Santa\_C](https://discourse.julialang.org/u/Hannah_Rocio_Santa_C)\
**Post date:** [March 2, 2021, 5:51am UTC](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304/1 "2021-03-02T05:51:57Z")

</div>

Hello,

I would like to plot several lines on a same plot.  
Each line was created with x in range [-1,1] as follows:

line\_x[i]=-1:0.1:1  
line\_y[i]=(a[i]\* line\_x[i] .+ b[I])

My problem is that for each line, I would like it to be plotted only on a specific window within the [-1,1]x[-1,1] square. (That is, I really only want pieces of my lines to appear on the plot). But I do want all my line pieces to appear on the same plot.

I tried:

plot!(line\_x[i], line\_y[i],xlim=(minX[i],maxX[i]),ylim=(minY[i],maxY[i]))

but it didn’t restrict the lines at all ☹

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [March 2, 2021, 6:00am UTC](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304/2 "2021-03-02T06:00:56Z")

</div>

`xlim` is a property of the subplot, not the series. What you want is to limit `x[i]`. How about

```julia
x[i] = xmin[i]:0.1:xmax[i]

```

?

---

<div class="post-metadata">

**Author:** ![Hannah\_Rocio\_Santa\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hannah_rocio_santa_c/32/21913_2.png) [@Hannah\_Rocio\_Santa\_C](https://discourse.julialang.org/u/Hannah_Rocio_Santa_C)\
**Post date:** [March 2, 2021, 6:08am UTC](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304/3 "2021-03-02T06:08:52Z")

</div>

That does work, thank you!

Is there a way I can also modify my y coordinates to be within minY and maxY, considering I am defining my y vector in function of the x vector?

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [March 2, 2021, 6:30am UTC](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304/4 "2021-03-02T06:30:30Z")

</div>

You can set those values in `y` to `missing`, for instance:

```julia
y[i] = map(t->t>ymax[i] ? missing : t, y[i])

```

Or remove offending `x`s:

```julia
filter!(t->f[i](t)<ymax[i], x[i])

```

If the y limits are global, doing `plot(..., ylim=(ymin, ymax))` should work.

---

<div class="post-metadata">

**Author:** ![Hannah\_Rocio\_Santa\_C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hannah_rocio_santa_c/32/21913_2.png) [@Hannah\_Rocio\_Santa\_C](https://discourse.julialang.org/u/Hannah_Rocio_Santa_C)\
**Post date:** [March 2, 2021, 6:58am UTC](https://discourse.julialang.org/t/plot-multiple-lines-with-different-ranges-in-same-plot/56304/6 "2021-03-02T06:58:04Z")

</div>

filter worked! thank you!!!
