Reputation: 11
Im trying to make the facility location problem algorithm ,and i got a possible solution , but dont know how to graph it,now im trying to use different layers by each binding line between the supplying center and the supplied point.For example , to make this two lines im using 2 different layers, with two different vectors: Supply point [1,1] and supplied points [5,2] and [2,6] as example:
using Gadfly
plot(layer(x=[1,5], y=[1,2],Geom.point, Geom.path),layer(x=[1,2], y=[1,6],Geom.point, Geom.path))
But, my issue is that i need to make it with hundreds of lines alike,many supplying and supplied points ,so i dont think proper to make a layer by bind. So , when try to make something like:
x=[1,2],[3,4]
y=[3,4],[2,4]
plot(layer(x[:], y[:],Geom.point, Geom.path))
I get a error. Regards
Upvotes: 0
Views: 207
Reputation: 181
See also Geom.segment, which is like Geom.vector
but without an arrow, and doesn't need explicit scales.
Upvotes: 0
Reputation: 871
In your example you assigned x=[1,2],[3,4]
which creates a tuple of arrays and Gadfly doesn't know how to handle it.
You'll need to provide the arrays as named parameters to plot:
xc = [0,1,0,-1,0,4,0,-2,0,-2]
yc = [0,3,0,-2,0,1,0,2,0,-2]
plot(x=xc, y=yc, Geom.path, Geom.point)
The important part if you use Geom.path
is to follow back to the supplying center, which is the point (0,0) in my example but could be any other. You'll need to prepare and interleave the data (x
and y
) on your own.
Another way would be to use Geom.vector
:
# coordinate system and scales are necessary for Geom.vector
coord = Coord.cartesian(xmin=-5, xmax=5, ymin=-5, ymax=5)
xsc = Scale.x_continuous(minvalue=-5, maxvalue=5)
ysc = Scale.y_continuous(minvalue=-5, maxvalue=5)
# prepare the points you want to show
xend = [1,-1,4,-2,-2]
yend = [3,-2,1,2,-2]
# create the supplying center (1,2)
x = fill(1,length(xend))
y = fill(2,length(yend))
#plot everything
plot(x=x,y=y,xend=xend,yend=yend,xsc,ysc,Geom.vector,coord)
Helpful documentation on Gadfly: http://gadflyjl.org/stable/index.html (take a look at Gallery->Geometries)
Upvotes: 0