8
$\begingroup$

I need to plot a graph (to be specific: Fortune Algorithm output) with given vertex coordinates and a few unconnected vertices. I am thinking of using Mathematica for that.

GraphPlot does much of the task with VertexCordinateRules option but does not plot unconnected points.

  1. So is there any way to do this?
    And it would be even nicer if that graph comes with 2-D Axes. I was thinking to use ListLinePlot and Point commands but they give two different graphs as output.

  2. Is there any option for combining output from two graphs? (The Show command didn't help.)

$\endgroup$
5
  • $\begingroup$ What version do you have? In version 8 you can use Graph instead of GraphPlot. Is your aim to construct an actual graph, or do you merely want to plot the result (and don't want to use it in a graph-context)? $\endgroup$
    – Szabolcs
    Commented Apr 25, 2012 at 13:17
  • $\begingroup$ I do have version 8, but Graph command doesn't seems to plot unconnected vertices. I don't think Computational geometry package will be helpful as I am looking for visualization only. $\endgroup$ Commented Apr 25, 2012 at 17:11
  • $\begingroup$ Actually, using adjacency matrix and graph plot I am able to plot unconnected vertices but the sense of Voronoi diagram is lost as graph plot does not follow coordinates systems(i.e. no directional or distance correctness). $\endgroup$ Commented Apr 25, 2012 at 17:42
  • $\begingroup$ @samikaran-theequation Just post a sample input dataset (in the format you have it in in Mathematica) and I'll show you how. $\endgroup$
    – Szabolcs
    Commented Apr 25, 2012 at 18:54
  • $\begingroup$ the option i was looking for is UndirectedEdge[] in graph command. :) $\endgroup$ Commented Apr 26, 2012 at 0:41

3 Answers 3

12
$\begingroup$

I didn't quite follow the description of your graph, but are you aware of this functionality?:

data = MapIndexed[Flatten[{##}] &, RandomReal[1, {100, 2}]];

ListDensityPlot[
 data,
 InterpolationOrder -> 0,
 ColorFunction -> Hue,
 Mesh -> All,
 Epilog -> Point@data[[All, {1, 2}]]
]

Mathematica graphics

Specifically note InterpolationOrder -> 0.

$\endgroup$
6
  • $\begingroup$ The ComputationalGeometry package has Voronoi diagrams as well. I think he's looking to visualize them only, not to compute them (suppose you'd make your own program for computing them, for whatever reason, then you need to visualize the result quickly) $\endgroup$
    – Szabolcs
    Commented Apr 25, 2012 at 13:16
  • $\begingroup$ You're not very active lately, what happened? I'm hoping for the glorious return of Spartacus! :D $\endgroup$
    – Szabolcs
    Commented Apr 25, 2012 at 13:18
  • $\begingroup$ Yup, I am looking just to plot my result of Voronoi diagram and not to compute them. Lets say; a={1,2};b={4,2};c={3,0};d={3,7}. So is there a way to plot an edge(c,d) and points a and b? $\endgroup$ Commented Apr 25, 2012 at 17:05
  • $\begingroup$ @Szabolcs other hobbies. :-) $\endgroup$
    – Mr.Wizard
    Commented Apr 25, 2012 at 17:56
  • 1
    $\begingroup$ Do you mean something like this? Graph[{a, b, c, d}, {UndirectedEdge[c,d]}, VertexCoordinates -> {{1, 2}, {4, 2}, {3, 0}, {3, 7}}] $\endgroup$
    – halmir
    Commented Apr 25, 2012 at 22:57
7
$\begingroup$

Here is a nice clean way to both compute and plot the Voronoi diagram with some undocumented functions:

Graphics`Region`RegionInit[];

Then:

pts = RandomReal[6, {100, 2}];

Show[GeometryPlot[VoronoiMesh[pts], Mesh -> All, 
  PlotStyle -> {Opacity[0.3], Yellow}, 
  MeshStyle -> {Darker@Green, Dashed}], Graphics[{Red, Point[pts]}]]

Mathematica graphics

$\endgroup$
6
$\begingroup$

Now in Mathematica 10, VoronoiMesh is a standard built in function.

pts=RandomReal[{-1,1},{25,2}];
Show[VoronoiMesh[pts]
    ,Graphics[{Red,Point[pts]}]
    ,Frame-> True
]

enter image description here

$\endgroup$
2
  • $\begingroup$ +1. I'm curious as no example was shown in the documentation. Does VoronoiMesh compute 3D Voronoi diagrams? $\endgroup$
    – RunnyKine
    Commented May 18, 2014 at 22:08
  • $\begingroup$ @RunnyKine tks. I see 3D in DelaunayMesh but not for VoronoiMesh. Maybe under implementation. $\endgroup$
    – Murta
    Commented May 18, 2014 at 22:14

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