3
$\begingroup$

I'm trying to create a plot legend where the rows contains multiple items, and those items have the same width, so that they appears to be in column. It should work with String Pad Right but for some reason the PlotLegends is deleting those paddings. Any idea on a workaround?

This works:

Column[
 Style[#[[1]] ~~ "    \[Sigma] = " ~~ #[[2]] ~~ 
     "    pkpk = " ~~ #[[3]], 15] & /@ Transpose@{
    StringPadRight[{"RxUsrClk", "Clean RxUsrClk"}],
    ToString[NumberForm[StandardDeviation[#], {10, 2}]] ~~ 
       " ps" & /@ {RandomReal[2, 50], RandomReal[3, 50]},
    ToString[NumberForm[Max[#] - Min[#], {10, 2}]] ~~ 
       " ps" & /@ {RandomReal[2, 50], RandomReal[3, 50]}
    }
 ]

And produces:

enter image description here

But inside the plot legends:

ListPlot[{RandomReal[2, 50], RandomReal[3, 50]},
 PlotLegends -> {
   Style[#[[1]] ~~ "    \[Sigma] = " ~~ #[[2]] ~~ 
       "    pkpk = " ~~ #[[3]], 15] & /@ Transpose@{
      StringPadRight[{"RxUsrClk", "Clean RxUsrClk"}],
      ToString[NumberForm[StandardDeviation[#], {10, 2}]] ~~ 
         " ps" & /@ {RandomReal[2, 50], RandomReal[3, 50]},
      ToString[NumberForm[Max[#] - Min[#], {10, 2}]] ~~ 
         " ps" & /@ {RandomReal[2, 50], RandomReal[3, 50]}
      }
   }]

It loses the right paddings:

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

Using a monospaced font:

With minimal changes to your code, it works fine.

ListPlot[{RandomReal[2, 50], RandomReal[3, 50]}, 
 PlotLegends -> {Style[#[[1]] ~~ "    \[Sigma] = " ~~ #[[2]] ~~ 
       "    pkpk = " ~~ #[[3]], 15, FontFamily -> "Courier"] & /@ 
    Transpose@{StringPadRight[{"RxUsrClk", "Clean RxUsrClk"}], 
      ToString[NumberForm[StandardDeviation[#], {10, 2}]] ~~ 
         " ps" & /@ {RandomReal[2, 50], RandomReal[3, 50]}, 
      ToString[NumberForm[Max[#] - Min[#], {10, 2}]] ~~ 
         " ps" & /@ {RandomReal[2, 50], RandomReal[3, 50]}}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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