plotjuliagadfly

Gadfly plots in the increasing order of x axis, and not in the order of the stored arrays


I am plotting some parameters from array using Gadfly in Julia 0.6.

Here is the output when I use Geom.point. I expect the dots to be connected as in this figure when using Geom.line, because the points in the array are stored in this order.

enter image description here

But when I use Geom.line, I get this:

enter image description here

It seems that Gadfly connects the dots in increasing order of x axes values irrespective of the order stored in the array. I do not get this kind of behavior in matlab. I am wondering what the remedy is.

Here is the code snippet for just one parameter (the green line). I have decreased the number of point for convenience:

x_axis = [22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 24.0, 30.0, 30.0, 30.0, 3.0]
y_axis = [-48, -44, -40, -36, -32, -28, -24, -20, -16,-12, -8, -4, 0]


fricPlot = plot(x = x_axis, y = y_axis, 
Theme(default_color=colorant"green"), Geom.point,
            Guide.xlabel("Scaled (a-b)/ Stress value"),
            Guide.ylabel("Depth (m)"),
            Guide.title("Rate and state friction/Stress"),
            Coord.Cartesian(ymin=-24))

How do I obtain a line plot which exactly looks like the points plot?


Solution

  • See Geom.path in the Gadfly docs. Example:

    t = 0:0.2:8pi
    plot(x=t.*cos.(t), y=t.*sin.(t), Geom.path)