# Elemental diagrams

This tweet came through my feed today:

Twitter user @MeijaJuris noted that this image is a bit out of date, given that nihonium (element 113, Nh) shares its abbreviation with New Hampshire. I wanted to see how to use Mathematica to update the diagram.

Here’s the code:

(* Grab data - state and element abbreviations *)
elements =
EntityClass["Element", All][
EntityProperty["Element", "AtomicSymbol"]];
states = Capitalize@
ToLowerCase@
(* Create overlap group and 'leftovers' *)
int = Intersection[elements, states];
juststates = DeleteCases[states, Alternatives @@ int];
justelements = DeleteCases[elements, Alternatives @@ int];
(* Create two regions that will be combined *)
a = Disk[{-0.5, 0}];
b = Disk[{0.5, 0}];
subsets = Subsets[{a, b}, {1, 2}];
(* Create the regions *)
regions =
DiscretizeRegion[
RegionDifference[BooleanRegion[And, #],
BooleanRegion[Or, Complement[{a, b, EmptyRegion[2]}, #]]]] & /@
subsets;
(* Use WordCloud to create region labels *)
WordCloud[#1, #2, WordSpacings -> {25, 25},
ColorFunction -> Black] &, {{juststates, justelements, int},
regions}];
(* Put everything together *)
RegionPlot[Evaluate@regions,
PlotLabels -> Callout[wc, Center, Background -> None],
LabelingSize -> 207, AspectRatio -> 1/1.09, Frame -> None,
ImageSize -> 400, BoundaryStyle -> Directive[Thickness[0.01], White],
Epilog -> {Text[Style["Elements", 14, Bold], {0.65, 1.1}],
Text[Style["States", 14, Bold], {-0.65, 1.1}]}]

The code is largely adapted from the documentation with some additions from the Wolfram Knowledge Base (or whatever it’s called nowadays). Once you learn the syntax (and that’s a huge hurdle), Entities contain a wealth of information that can be useful in any number of applications. The easiest way I’ve found to explore Entities is by using the natural language input feature to perform a search, which is accessed by starting a cell with =, and then converting the cell to input form to see how it was done:

Still, there’s the tricky part of making sure you know what is a string and what isn’t. That part requires a bit of trial and error. Perhaps there’s a simpler way to do this, but for now, it’s an approach that is working for me.

This site uses Akismet to reduce spam. Learn how your comment data is processed.