Network Graphs in F#
How to make Network Graphs in Python with Plotly. One examples of a network graph with NetworkX
In [1]:
#r "nuget: Plotly.NET, 2.0.0-preview.8"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.8"
Create Nodes¶
In [2]:
//open QuickGraph
open Plotly.NET
open Plotly.NET.LayoutObjects
let x = [2;3;5;1;10;3]
let y = [12;14;7;2;15;4]
Chart.Point(x,y)
|> Chart.withMarkerStyle(Size=10)
|> Chart.withXAxis(LinearAxis.init(ShowTickLabels=false,ShowGrid=false,ShowLine=false))
|> Chart.withYAxis(LinearAxis.init(ShowTickLabels=false,ShowGrid=false,ShowLine=false))
Out[2]:
Create Edges¶
In [3]:
open System
let rand = new Random()
let x = [for i in 0..100 -> rand.Next(0,100) ]
let y = [for i in x -> rand.Next(0,100) ]
let edges = [for i in x -> let i = rand.Next(0,100)
let j = rand.Next(0,100)
Shape.init(StyleParam.ShapeType.Line,X0=x.[i],X1=x.[j],Y0=y.[i],Y1=y.[j],Line=Line.init(Color=Color.fromString "#888",Width=0.5))]
Chart.Point(x,y)
|> Chart.withMarkerStyle(Size=10)
|> Chart.withXAxis(LinearAxis.init(ShowTickLabels=false,ShowGrid=false,ShowLine=false,ZeroLine=false))
|> Chart.withYAxis(LinearAxis.init(ShowTickLabels=false,ShowGrid=false,ShowLine=false,ZeroLine=false))
|> Chart.withShapes edges
Out[3]: