# Plotting weighted graphs

**URL:** https://discourse.julialang.org/t/plotting-weighted-graphs/43127
**Category:** Visualization
**Tags:** question, plotting
**Created:** [July 15, 2020, 1:11pm UTC](https://discourse.julialang.org/t/plotting-weighted-graphs/43127 "2020-07-15T13:11:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)
#### Post date: [July 15, 2020, 1:11pm UTC](https://discourse.julialang.org/t/plotting-weighted-graphs/43127/1 "2020-07-15T13:11:58Z")

</div>

Is it possible to plot a `SimpleWeightedGraphs.SimpleWeightedDiGraph`?  
Using `GraphPlot` I get an error.

---

<div class="post-metadata">

### Author: ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)
#### Post date: [July 15, 2020, 1:49pm UTC](https://discourse.julialang.org/t/plotting-weighted-graphs/43127/2 "2020-07-15T13:49:36Z")

</div>

It would be very helpful if you provide more information about your situation.  
For example: Which kind of data do you want to plot? Where do you get your weights from? What have you done so far? Which error do you get? Can you provide a MWE to reproduce the error?

To answer your general question: yes, it is possible to plot a `SimpleWeightedDiGraph`. Have you had a look at the [general examples of SimpleWeightedGraphs.jl](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl) ?

---

<div class="post-metadata">

### Author: ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)
#### Post date: [July 16, 2020, 7:43am UTC](https://discourse.julialang.org/t/plotting-weighted-graphs/43127/3 "2020-07-16T07:43:22Z")

</div>

The weights are a lose representation of the geographic distance of the nodes. But I don’t see why this would be important.

```julia
using LightGraphs, SimpleWeightedGraphs, GraphPlot

g = SimpleWeightedGraph(3)  
add_edge!(g, 1, 2, 0.5)
add_edge!(g, 2, 3, 0.8)
add_edge!(g, 1, 3, 2.0)

gplot(g)

```

> ERROR: LoadError: MethodError: no method matching \_src\_index(::SimpleWeightedEdge{Int64,Float64}, ::SimpleWeightedGraph{Int64,Float64})  
> Closest candidates are:  
> \_src\_index(::LightGraphs.SimpleGraphs.SimpleEdge, ::AbstractGraph)

However, using

```julia
loc_x, loc_y = spring_layout(g)

```

and drawing it myself works.

---

<div class="post-metadata">

### Author: ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)
#### Post date: [July 16, 2020, 12:14pm UTC](https://discourse.julialang.org/t/plotting-weighted-graphs/43127/4 "2020-07-16T12:14:45Z")

</div>

Following [the instructions for GraphPlot](https://juliagraphs.org/LightGraphs.jl/stable/plotting/#%5BGraphPlot.jl%5D(https://github.com/afternone/GraphPlot.jl)-1), I’ve not been able to plot it as well. There seems to be no method for SimpleWeightedGraphs.

Maybe consider asking for such an extension in the issues section of the GraphPlot github repo. I’ve found this [related issue on the SimpleWeightedGraphs repo](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl/issues/45).
