'GraphPlots - Is there a way to have different colors for edges?
Given GraphPlots doc, we have the following available attributes:
function gplot{V, T<:Real}(
G::AbstractGraph{V},
locs_x::Vector{T}, locs_y::Vector{T};
nodelabel::Union(Nothing, Vector) = nothing,
nodelabelc::ComposeColor = colorant"black",
nodelabelsize::Union(Real, Vector) = 4,
nodelabeldist::Real = 0,
nodelabelangleoffset::Real = π/4.0,
edgelabel::Union(Nothing, Vector) = nothing,
edgelabelc::ComposeColor = colorant"black",
edgelabelsize::Union(Real, Vector) = 4,
edgestrokec::ComposeColor = colorant"lightgray",
edgelinewidth::Union(Real, Vector) = 1,
edgelabeldistx::Real = 0,
edgelabeldisty::Real = 0,
nodesize::Union(Real, Vector) = 1,
nodefillc::ComposeColor = colorant"turquoise",
nodestrokec::ComposeColor = nothing,
nodestrokelw::Union(Real, Vector) = 0,
arrowlengthfrac::Real = Graphs.is_directed(G) ? 0.1 : 0.0,
arrowangleoffset = 20.0/180.0*π)
With edgestrokec
allowing to change edge's color. However, I have two types of edges in my graph and I would like to color them in two different colors. Is it possible?
if !plot_backup_edge
for i in 1:length(hubs)-1
add_edge!(inst_graph, hubs[i], hubs[i+1])
## TODO: Have a first color here for the edges
end
add_edge!(inst_graph, hubs[1], hubs[end])
end
if plot_backup_edge
for i in 2:length(hubs)-1
add_edge!(inst_graph, hubs[i-1], hubs[i+1])
## TODO: Have a second color here for the edges
end
add_edge!(inst_graph, hubs[end-1], hubs[2])
end
Solution 1:[1]
Use edgestrokec
:
using Colors
G = Graph(8,12)
gplot(G;edgestrokec =rand([colorant"red", colorant"green", colorant"blue"],12))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Przemyslaw Szufel |