11
$\begingroup$

I have tried using the option MultiedgeStyle->None, but apparently Mathematica doesn't treat self loops in the same way it treats edges. For example, I find

GraphPlot[{{1,2},{2,0}}, SelfLoopStyle->All, MultiedgeStyle->None]

Graph with one self loop

while the same command, but with twice the weight on the self loop gives

GraphPlot[{{2,2},{2,0}}, SelfLoopStyle->All, MultiedgeStyle->None]

enter image description here

I would like the output from both commands to be the same. I know I could write a function to replace all non-zero values on the diagonal with 1, but I'd prefer not to for two reasons. One is that it seems as if this should be possible without resorting to that, and the other is that I'm actually using this inside another routine to draw graphs with edge weights displayed, to get output such as

enter image description here

where the label inside the self loop should list the correct weight, taken from the diagonal of the adjacency matrix. Removing the diagonals for later labeling then changing them in the adjacency matrix just seems like a hack.

$\endgroup$
3
  • 2
    $\begingroup$ Can you post your matrix? If the matrix isn't composed of 0's and 1's, it's not an AdjacencyMatrix[]. It can be a DistanceMatrix[], a WeightedAdjacencyMatrix[] or something else... Luckily Mathematica offers more than one way to visualise graphs - I've already encountered some problems too. $\endgroup$
    – CHM
    Commented Mar 29, 2012 at 1:46
  • $\begingroup$ I posted two of the matrices in the examples in my question: {{1,2},{2,0}} and {{2,2},{2,0}}. So I guess they would both be given by WeightedAdjacencyMatrix[g] instead of AdjacencyMatrix[g] if I had started with some graph g, but I'm just working directly with real symmetric matrices that represent weighted undirected graphs. Can you point me to some of those other ways to visualise graphs? I'm only familiar with GraphPlot[]. Thanks! $\endgroup$ Commented Mar 29, 2012 at 3:50
  • $\begingroup$ I was trying to write an answer, but it turns out this is not a trivial problem. I was hoping for "EdgeWeights" to work, but it doesn't. $\endgroup$
    – CHM
    Commented Mar 29, 2012 at 4:56

1 Answer 1

8
$\begingroup$

A simple hack of a way to obtain the behaviour that you want is to negate the adjacency matrix. Now, don't ask me what that means or represents, but it works!

enter image description here

Modifying the example from the accepted answer in the question that CHM shared to include multiple self loops:

enter image description here

You can see that the second one displays the behaviour you want.

$\endgroup$
3
  • $\begingroup$ That was unexpected. It's nice, but he still has to work with two matrices: the adjacency matrix and its negative. I removed my answer because it was basically a solution the inquirer did not want, as he describes in his question. Anyhow, +1 for finding this! $\endgroup$
    – CHM
    Commented Mar 29, 2012 at 23:41
  • $\begingroup$ Umm.. I wouldn't really consider a matrix and its negative as two different matrices :) It should be a fairly trivial change to incorporate this in his code $\endgroup$
    – rm -rf
    Commented Mar 29, 2012 at 23:44
  • 2
    $\begingroup$ Now ... I am really curious about how did you find it :) $\endgroup$ Commented Mar 30, 2012 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.