Skip to main content
added 1184 characters in body
Source Link

Edit 02

There was a small bug in dealing with empty sets (e.g. the one that arises with the chosen random seed below). This is now fixed. Additionally, figured I'd play around with the new-ish HardcorePointProcess functionality to get more evenly-spaced labels. Seems to work reasonably well (you might have to adjust the radius, r0):

shrinkPolygon[polygon_,sf_:0.85] := TransformedRegion[polygon,ScalingTransform[{sf, sf}, RegionCentroid[polygon]]]

postProcessVennDiagram[vd_] := 
 Block[{labels, polygons, rpts, text, r0, hs},
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  r0 = 32/(Sqrt[n] Sqrt[\[Pi]]) /. n -> Length[Join @@ labels];
  hs = HardcorePointProcess[1000, r0, 2];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[Take[RandomPointConfiguration[hs, DiscretizeRegion[#1]]["Points"]shrinkPolygon[DiscretizeRegion[#1]]]["Points"], #2] &, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description hereenter image description here

Seems to work reasonably well. Note you might have to adjust the radius, r0, and scaling factor, sf, in the polygon shrinking (which I added to ensure the labels are completely maintained inside the regions).

Edit 01

It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get them more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text}, 
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description here

Original Answer

There's a very nice Function Repository entry that makes this quite easy:

SeedRandom[25];
vd=With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description here

Edit 02

There was a small bug in dealing with empty sets (e.g. the one that arises with the chosen random seed below). This is now fixed. Additionally, figured I'd play around with the new-ish HardcorePointProcess functionality to get more evenly-spaced labels. Seems to work reasonably well (you might have to adjust the radius, r0):

postProcessVennDiagram[vd_] := 
 Block[{labels, polygons, rpts, text, r0, hs},
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  r0 = 3/(Sqrt[n] Sqrt[\[Pi]]) /. n -> Length[Join @@ labels];
  hs = HardcorePointProcess[1000, r0, 2];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[Take[RandomPointConfiguration[hs, DiscretizeRegion[#1]]["Points"], #2] &, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description here

Edit 01

It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get them more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text}, 
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description here

Original Answer

There's a very nice Function Repository entry that makes this quite easy:

vd=With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description here

Edit 02

There was a small bug in dealing with empty sets (e.g. the one that arises with the chosen random seed below). This is now fixed. Additionally, figured I'd play around with the new-ish HardcorePointProcess functionality to get more evenly-spaced labels:

shrinkPolygon[polygon_,sf_:0.85] := TransformedRegion[polygon,ScalingTransform[{sf, sf}, RegionCentroid[polygon]]]

postProcessVennDiagram[vd_] := 
 Block[{labels, polygons, rpts, text, r0, hs},
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  r0 = 2/(Sqrt[n] Sqrt[\[Pi]]) /. n -> Length[Join @@ labels];
  hs = HardcorePointProcess[1000, r0, 2];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[Take[RandomPointConfiguration[hs, shrinkPolygon[DiscretizeRegion[#1]]]["Points"], #2] &, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description here

Seems to work reasonably well. Note you might have to adjust the radius, r0, and scaling factor, sf, in the polygon shrinking (which I added to ensure the labels are completely maintained inside the regions).

Edit 01

It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get them more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text}, 
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description here

Original Answer

There's a very nice Function Repository entry that makes this quite easy:

SeedRandom[25];
vd=With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description here

added 1184 characters in body
Source Link

Edit 02

There'sThere was a very nicesmall bug in dealing with empty sets Function Repository entry(e.g. the one that makes this quite easyarises with the chosen random seed below). This is now fixed. Additionally, figured I'd play around with the new-ish HardcorePointProcess functionality to get more evenly-spaced labels. Seems to work reasonably well (you might have to adjust the radius, r0):

vd=With[{postProcessVennDiagram[vd_] := 
 Block[{labels, apolygons, =rpts, RandomSample[Range[3text, 30]r0, 20]hs},
  blabels = RandomSample[Range[2vd[[2, 40]All, 20]2, 1, 1, 1, 1]];
  cr0 = RandomSample[Range[43/(Sqrt[n] Sqrt[\[Pi]]) /. n -> Length[Join @@ labels];
  hs = HardcorePointProcess[1000, 49]r0, 20]2];
  }polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
 ResourceFunction["VennDiagram"][ rpts = MapThread[Take[RandomPointConfiguration[hs, DiscretizeRegion[#1]]["Points"], #2] &, {apolygons, bLength /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, c16], #2] &, {Join @@ labels, Join @@ rpts}]]];
 ] Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description hereenter image description here

Edit 01

Edit: It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPointRandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get thethem more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text}, 
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  length = Length[labels];
  polygons = vd[[1Cases[vd[[1, 11]], 2 ;; length 2{Null, ;;Polygon[a__]} 2,:> 2]];Polygon[a]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@labels@@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]350]]

postProcessVennDiagram[vd]

enter image description here

Original Answer

There's a very nice Function Repository entry that makes this quite easy:

vd=With[{
  ]a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
postProcessVennDiagram[vd]  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description hereenter image description here

There's a very nice Function Repository entry that makes this quite easy:

vd=With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description here

Edit: It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get the more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text},
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  length = Length[labels];
  polygons = vd[[1, 1, 2 ;; length 2 ;; 2, 2]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]
  ]

postProcessVennDiagram[vd]

enter image description here

Edit 02

There was a small bug in dealing with empty sets (e.g. the one that arises with the chosen random seed below). This is now fixed. Additionally, figured I'd play around with the new-ish HardcorePointProcess functionality to get more evenly-spaced labels. Seems to work reasonably well (you might have to adjust the radius, r0):

postProcessVennDiagram[vd_] := 
 Block[{labels, polygons, rpts, text, r0, hs},
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  r0 = 3/(Sqrt[n] Sqrt[\[Pi]]) /. n -> Length[Join @@ labels];
  hs = HardcorePointProcess[1000, r0, 2];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[Take[RandomPointConfiguration[hs, DiscretizeRegion[#1]]["Points"], #2] &, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description here

Edit 01

It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get them more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text}, 
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  polygons = Cases[vd[[1, 1]], {Null, Polygon[a__]} :> Polygon[a]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@ labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]]

postProcessVennDiagram[vd]

enter image description here

Original Answer

There's a very nice Function Repository entry that makes this quite easy:

vd=With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description here

added 789 characters in body
Source Link

There's a very nice Function Repository entry that makes this quite easy:

With[vd=With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description hereenter image description here

Edit: It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get the more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text},
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  length = Length[labels];
  polygons = vd[[1, 1, 2 ;; length 2 ;; 2, 2]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]
  ]

postProcessVennDiagram[vd]

enter image description here

There's a very nice Function Repository entry that makes this quite easy:

With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description here

There's a very nice Function Repository entry that makes this quite easy:

vd=With[{
  a = RandomSample[Range[3, 30], 20],
  b = RandomSample[Range[2, 40], 20],
  c = RandomSample[Range[4, 49], 20]
  },
 ResourceFunction["VennDiagram"][{a, b, c}]
 ]

enter image description here

Edit: It should be possible to post-process the result to place the elements inside their corresponding region. For example, here I'm using RandomPoint but I suspect you can use some sort of Lloyd relaxation on a voronoi mesh to get the more evenly spaced:

postProcessVennDiagram[vd_] := 
 Block[{labels, length, polygons, rpts, text},
  labels = vd[[2, All, 2, 1, 1, 1, 1]];
  length = Length[labels];
  polygons = vd[[1, 1, 2 ;; length 2 ;; 2, 2]];
  rpts = MapThread[RandomPoint, {polygons, Length /@ labels}];
  text = Graphics[MapThread[Text[Style[#1, 16], #2] &, {Join @@labels, Join @@ rpts}]];
  Show[vd[[1]], text, ImageSize -> 350]
  ]

postProcessVennDiagram[vd]

enter image description here

Source Link
Loading