# Plotting two lines on one plot over the same x range but with different x arrays in Plots.jl

I would like to plot two line plots on the same plot, however I have two sets of data and while for both sets the x domain range is the same (0,.25) the values which are paired with my data are different. Is there a way to put two plots together if they have the same x range but different specific x values?

There shoudn’t be any problem:

``````using Plots
x1 = collect(1:3:12)
y1 = rand(4)
x2 = collect(1:4:12)
y2= rand(3)
plot(x1,y1)
plot!(x2,y2)
``````

Edit: indeed, it doesn’t work…
Edit2: sure it works… with plot!(.)

1 Like

do you mean `plot!(x2,y2)`

``````julia> scatter(x1,y1); scatter!(x2, y2)
``````

1 Like

This works for me:

``````using Plots
x1 = collect(1:3:12)
y1 = rand(4)
x2 = collect(1:4:12)
y2= rand(3)
plot([x1,x2],[y1,y2])

``````

Yours works for me on Julia 1.3 rc4 with GR backend.

Sure… typed it with my mobile during the night after making asleep a crying baby haha…

1 Like

Thank you! My problem, for the record, was I was trying to re-label the axes and plot title in the plot!() command (with the same labels), which is nonsensical because they are already specified.

I am now not being able to get `plot!(x1,y2, label = ["y2 label"])` to work to label the second line plot. What command can I use for this? Sorry, I am sure this is in the documentation but I could not find it.

Not 100% what the problem is. With `using Plots` and `pyplot()` backend, I create some data (using functions):

``````x1 = range(5,15,length=20)
x2 = range(10,20,length=100)
f1 = x-> exp(-(x-10)^2/5^2)
f2 = x-> sin(2pi*(x-15))/(2pi*(x-15))
y1 = f1.(x1)
y2 = f2.(x2);
``````

Plots are produced by:

``````plot(x1,y1,label="f1")
plot!(x2,y2,label="f2")
plot!(xlim=(0,25))
``````

giving:

Is it something like this that you want?

2 Likes

Appreciate u men!