3
$\begingroup$

I've a problem with the legend of my graph. I've customized the graphs of my papers in an acceptable way for the a lot of journals. But this time I've two problem:

  1. Is there a simple way to write the names of compounds? I've written them by hand!

  2. The real problem is: the legend is too long. I tried to move it on the right or below the graph, but it is not acceptable.

Is there a way to divide the legend in columns or another pretty way that I do not know?

 data =
   {
     {{0.388677, 9.93}, {0.352228, 8.57}}, 
     {{0.53975, 15.65}, {0.53114, 15.4}, {0.522233, 15.}, 
      {0.521965, 14.92}, {0.513295, 14.7}}, 
     {{0.442124, 16.96}, {0.420902, 15.89}}, {{0.500897, 21.9}}, 
     {{0.5643, 26.66}}, {{0.573449, 16.97}}, 
     {{0.557509, 16.}, {0.54885, 15.84}}, 
     {{0.660017, 19.6}}, {{0.61177, 37.5}}, {{0.363762, 11.09}}, 
     {{0.355667, 11.5}}, {{0.423394, 16.65}}, {{0.285016, 9.44}}, 
     {{0.583312, 15.85}}, {{0.310173, 8.18}}, {{0.485398, 14.26}}, 
     {{0.467278, 14.06}}, {{0.413139, 15.73}}, {{0.569744, 16.1}}, 
     {{0.469172, 16.75}}, {{0.401343, 13.68}}, {{0.405889, 15.52}}, 
     {{0.410936, 14.54}}
   };

 compoundName = {"Decamethylcyclopentasiloxane", 
 "Decamethyltetrasiloxane", "Dimethyldichlorosilane", 
 "Dimethyldimethoxysilane", "Diphenyldichlorosilane", 
 "Dodecamethylcyclohexasiloxane", "Dodecamethylpentasiloxane", 
 "Eicosamethylnonasiloxane", "Gamma-aminopropyltriethoxysilane", 
 "Hexamethylcyclotrisiloxane", "Hexamethyldisilazane", 
 "Methyl Dichlorosilane", "Methyl Trichlorosilane", 
 "Octadecamethyloctasiloxane", "Octamethylcyclotetrasiloxane", 
 "Octamethyltrisiloxane", "Silane", "Tetrachlorosilane", 
 "Tetradecamethylhexasiloxane", "Tetraethoxysilane", 
 "Tetraethyl Silane", "Trichlorosilane", "Trimethylchlorosilane"};

 colours = {Red, Blue, Green, Darker[LightBlue], Black, LightBlue, 
 Cyan, Gray, Magenta, Brown, Orange, Pink, Purple, Darker[Purple], 
 Darker[Red], Yellow, Darker[Yellow], Darker[Cyan], Darker[Magenta],
 Darker[Brown], Darker[Pink], Darker[Purple], Darker[Green]};

 par1 = 13;
 par2 = 20;

 plot = ListPlot[data, 
   PlotMarkers -> {
     {"●", par2}, {"▲", par2}, 
     {"△", par2}, {"▽", par2}, 
     {"▼", par2}, {"◀", par2}, 
     {"▶", par2}, {"○", par2}, 
     {"◆", par2}, {"■", par2}, 
     {"★", par2}, {"□", par2}, 
     {"◇", par2}, {"*", par2}, 
     {"▯", par2}, {"\[DottedSquare]", par2}, 
     {"\[GraySquare]", par2}, {"\[CheckedBox]", par2}, 
     {"✶", par2}, {"⧏", par2}, 
     {"⊴", par2}, {"⧐", par2}, 
     {"⊵", par2}}, 
   PlotStyle -> colours, 
   ImageSize -> 500, 
   PlotLegends -> 
     Placed[{
       Style["Decamethylcyclopentasiloxane", par1], 
       Style["Decamethyltetrasiloxane", par1], 
       Style["Dimethyldichlorosilane", par1], 
       Style["Dimethyldimethoxysilane", par1], 
       Style["Diphenyldichlorosilane", par1], 
       Style["Dodecamethylcyclohexasiloxane", par1], 
       Style["Dodecamethylpentasiloxane", par1], 
       Style["Eicosamethylnonasiloxane", par1], 
       Style["Gamma-aminopropyltriethoxysilane", par1], 
       Style["Hexamethylcyclotrisiloxane", par1], 
       Style["Hexamethyldisilazane", par1], 
       Style["Methyl Trichlorosilane", par1], 
       Style["Methyl Trichlorosilane", par1], 
       Style["Octadecamethyloctasiloxane", par1], 
       Style["Octamethyltrisiloxane", par1], 
       Style["Silane", par1], 
       Style["Tetrachlorosilane", par1], 
       Style["Tetradecamethylhexasiloxane", par1], 
       Style["Tetraethoxysilane", par1], 
       Style["Tetraethyl Silane", par1], 
       Style["Trichlorosilane", par1],
       Style["Trimethylchlorosilane", par1]}, 
     Bottom], 
   Frame -> {{True, False}, {True, False}}, 
   FrameLabel -> 
     {Style["(1-Tr\!\(\*SuperscriptBox[\()\), 
        StyleBox[\"B\",\nFontWeight->\"Plain\"]]\)", 18], 
      Style["\!\(\*SubscriptBox[\(σ\), \(exp\)]\)(mN·\  
        \!\(\*SuperscriptBox[\(m\), \(-1\)]\))", 
        18]}, 
   FrameStyle -> 15, 
   PlotRange -> All]

The effect is

image

Any suggestions will be appreciated.

$\endgroup$
  • 2
    $\begingroup$ I have seen many times in journals that in such cases the notations are given in a caption, rather than in a legend: "Red disk decamethylcyclo..., vertex-up filled triangle - decamethyltetra..." and so on. Another way may be in a journal with the two-column layout to make a figure with the width corresponding to two columns, its left panel being the figure itself, while its right one containing a table of legends. $\endgroup$ – Alexei Boulbitch Jun 15 '15 at 11:51
  • $\begingroup$ It might be tidier to use structural formulae instead, e.g. $(\rm{Me}_3\rm{Si})_2\rm{NH}$ for hexamethyldisilazane. $\endgroup$ – J. M.'s technical difficulties Jun 15 '15 at 12:44
11
$\begingroup$

Yes, and yes!

  1. You do need to enter all the names of the compounds once (as in the list compoundName), but after that, you can make Mathematica do the rest. As Guess who it is suggests, you can make these names considerably more compact by specifying the chemical formulae. On a side note, Mathematica has access to curated chemical data via ChemicalData, which recognizes some of the chemicals, so you can retrieve some (but not, alas, all) of the formulae via

    formulae = ChemicalData[#, "Formula"] & /@ Interpreter["Chemical"] /@ compoundName
    

    Conversely, you could specify the formulae names as a string and use the Interpreter and ChemicalData to turn them into long-form names. For instance,

    ChemicalData[Interpreter["Chemical"]["C10H30O5Si5"], "Name"]
    
    "decamethylcyclopentasiloxane"
    

    Again, this will only work for some of your chemicals!

  2. You can specify a LegendLayout to arrange the legend into rows or columns or whatnot. To do this, however, you do need to construct the legend explicitly, in this case with PointLenged. You can also add a panel or a frame to the legend using LegendFunction.


Example implementation

Using your definitions of data, compoundName (I removed "Methyl Dichlorosilane", since you didn't seem to use it), colours, par2, and par2,

markers = {
   "\[FilledCircle]", "\[FilledUpTriangle]", "\[EmptyUpTriangle]", "\[EmptyDownTriangle]", 
   "\[FilledDownTriangle]", "\[FilledLeftTriangle]", "\[FilledRightTriangle]", 
   "\[EmptyCircle]", "\[FilledDiamond]", "\[FilledSquare]", "\[FivePointedStar]", 
   "\[EmptySquare]", "\[EmptyDiamond]", "*", "\[EmptyRectangle]",  "\[DottedSquare]", 
   "\[GraySquare]", "\[CheckedBox]", "\[SixPointedStar]", "\[LeftTriangleBar]", 
   "\[LeftTriangleEqual]", "\[RightTriangleBar]", "\[RightTriangleEqual]"
  };

xlabel = "(1-Tr\!\(\*SuperscriptBox[\()\), StyleBox[\"B\",\n\ FontWeight->\"Plain\"]]\)";
ylabel = "\!\(\*SubscriptBox[\(\[Sigma]\), \(exp\)]\)(mN\[CenterDot]\ \!\(\*SuperscriptBox[\(m\), \(-1\)]\))";

plot = ListPlot[data,
  PlotMarkers -> Evaluate[{#, par2} & /@ markers],
  PlotStyle -> colours,
  ImageSize -> 500, 
  PlotLegends -> Placed[
    PointLegend[
     colours,
     Style[#, par1] & /@ compoundName,
     LegendMarkers -> markers,
     LegendLayout -> {"Column", 2}],
    Right],
  Frame -> {{True, False}, {True, False}},
  FrameLabel -> {Style[xlabel, 18], Style[ylabel, 18]},
  FrameStyle -> 15,
  PlotRange -> All
  ]

plot

|improve this answer|||||
$\endgroup$
  • $\begingroup$ This is what I need. Thanks!! $\endgroup$ – meriens Jun 15 '15 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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