2
$\begingroup$

I have got a graph in GML format (see attachment). I imported it on the Mathematica.

g=Import["~/K33_2.gml ", ImagePadding -> 10]

With the guarantee that its layout will not change, I want to reduce the size of the vertices. I tried to change them with VertexSize. But it doesn't work. (Graph[g, VertexSize -> 0.01 ])

enter image description here


I don't find an interface for attachment uploads on this platform. So I pasted the text as below.

K33_2.gml

  graph
[
    hierarchic  1
    label   ""
    undirected  1
    node
    [
        id  1
        label   "b1"
        graphics
        [
            x   540
            y   640
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#0000FF"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "b1"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  2
        label   "b2"
        graphics
        [
            x   600
            y   320
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#0000FF"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "b2"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  3
        label   "r1"
        graphics
        [
            x   660
            y   160
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#FF0000"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "r1"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  4
        label   "r2"
        graphics
        [
            x   300
            y   320
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#FF0000"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "r2"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  5
        label   "r3"
        graphics
        [
            x   1080
            y   0
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#0000FF"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "r3"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  6
        label   "x6"
        graphics
        [
            x   900
            y   80
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#D228C2"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "x6"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  7
        label   "x7"
        graphics
        [
            x   540
            y   240
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#D228C2"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "x7"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  8
        label   "b3"
        graphics
        [
            x   360
            y   400
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#0000FF"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "b3"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    node
    [
        id  9
        label   "x9"
        graphics
        [
            x   540
            y   720
            w   30.0
            h   15.0
            type    "ellipse"
            raisedBorder    0
            fill    "#D228C2"
            outline "#000000"
        ]
        LabelGraphics
        [
            text    "x9"
            color   "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            anchor  "c"
        ]
    ]
    edge
    [
        source  3
        target  6
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r1"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  9
        target  4
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r2"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  3
        target  2
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r1"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  7
        target  4
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r2"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  1
        target  5
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r3"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  6
        target  1
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r1"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  5
        target  6
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r3"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  6
        target  2
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r3"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  2
        target  7
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r2"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  3
        target  7
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r1"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  7
        target  8
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r1"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  8
        target  4
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r2"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  1
        target  9
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r2"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  8
        target  9
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r3"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
    edge
    [
        source  9
        target  5
        graphics
        [
            fill    "#000000"
        ]
        LabelGraphics
        [
            text    "r3"
            fill    "#FFFFFF"
            fontSize    12
            fontName    "Dialog"
            configuration   "AutoFlippingLabel"
            contentWidth    36
            contentHeight   20
            model   "centered"
            position    "center"
        ]
    ]
]
$\endgroup$
1
  • 1
    $\begingroup$ you could reset by pattern: Graph[g, VertexSize -> {_ -> .01}] $\endgroup$
    – halmir
    Commented Jul 26, 2022 at 18:21

1 Answer 1

4
$\begingroup$

Each vertex has a size set separately. Thus changing the global VertexSize of the graph will have no effect. One solution would be to set a new size for each vertex, but this is not nice. Instead, we first remove all VertexSize settings, then re-add a global one:

Annotate[AnnotationDelete[g, VertexSize], VertexSize -> 0.5]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks. How do I get the property of the size of all the vertices of a graph? $\endgroup$
    – licheng
    Commented Jul 26, 2022 at 8:19
  • 1
    $\begingroup$ AnnotationValue[g, VertexSize] seems to work, but I don't see what the output means. {1 -> {30., 15.}, 9 -> {30., 15.}, 4 -> {30., 15.}, 2 -> {30., 15.}, 5 -> {30., 15.}, 8 -> {30., 15.}, 3 -> {30., 15.}, 7 -> {30., 15.}, 6 -> {30., 15.}} $\endgroup$
    – licheng
    Commented Jul 26, 2022 at 9:07
  • 1
    $\begingroup$ 1 -> {30, 15} means that vertex 1 is 30 units wide and 15 units tall. $\endgroup$
    – Szabolcs
    Commented Jul 26, 2022 at 10:02

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.