Plot multiple lines with different ranges in same plot

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 :frowning:

Thanks for your help!

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

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

?

2 Likes

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?

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

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

Or remove offending xs:

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

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

1 Like

filter worked! thank you!!!