Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to make a graph using a file .NET extracted from a file .CSV and to make tooltiped the vertices' labels.

Initially I have extracted an IncidentMatrix and then VertexLabels.

IncidenceGraph[
 IncidenceMatrix[Import["C:\\Users\\Network.net"]], 
 AbsoluteOptions[Import["C:\\Users\\Network.net"], VertexLabels]]

I wasn't able to made it by using Placed. What else can i do?

For example, I define an array that contains all labels and an incidence matrix:

Labels = {1 -> "One", 2 -> "Two", 3 -> "Three"}; Matrix = {1 <-> 2, 2 <-> 3, 3 <-> 1}; Graph[Matrix, VertexLabels -> Placed[Labels, Tooltip]]

But it the only one label viewed is "Three". I can also use a code like this:

Matrix = {1 <-> 2, 2 <-> 3, 3 <-> 1}; Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, VertexLabels -> {1 -> Placed["one", Tooltip], 2 -> Placed["two", Tooltip], 3 -> Placed["three", Tooltip]}] But in this case I'm supposed to insert the labels one by one.

share|improve this question
1  
How does your work set differ from the documentation example IncidenceGraph[( {{0, 1, 1}, {1, 0, 1}, {1, 1, 0}} ), EdgeLabels -> Placed["Name", Tooltip]]? Can you give us a self-contained example where that doesn't work? –  Mr.Wizard Jan 14 at 16:16

1 Answer 1

up vote 0 down vote accepted
matrix = {1 <-> 2, 2 <-> 3, 3 <-> 1};
labels = {1 -> "One", 2 -> "Two", 3 -> "Three"};

You can modify labels programmatically using

labels1 = (# -> Placed[#2, Tooltip] & @@@ labels);

or using

labels2 = MapAt[Placed[#, Tooltip] &, labels, {All, -1}];

Alternatively, you can use the function Property to set the VertexLabels for each vertex:

labeledvertices = Property[#, VertexLabels -> Placed[#2, Tooltip]] & @@@ labels;

All three methods give the same result:

g1 = Graph[matrix, VertexLabels -> labels1];
g2 = Graph[matrix, VertexLabels -> labels2];
g3 = Graph[labeledvertices, matrix];

Grid[{{"g1", "g2", "g3"}, {g1, g2, g3}}, Frame -> {All, None}]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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