TransWikia.com

`PlotLabel` for plots in a `Table`

Mathematica Asked by Richard Burke-Ward on February 1, 2021

I have a Table containing two plots, given by

Table[
 Plot[{Re[f[n]] /. j -> 3, Im[f[n]] /. j -> 3}, {n, 0, 15}, 
  GridLines -> Automatic, PlotRange -> All, PlotLegends -> {"Real", "Imaginary"}, 
  PlotLabel -> f[n]], 
{f, {Sum[Sinc[Pi*(#1 - i*j)], {i, 1, Floor[#1]}] & , 
   (-1 + E^(2*I*Pi*#1))/(j*(-1 + E^((2*I*Pi*#1)/j))) & }}
]

enter image description here

As you can see, Mathematica has rewritten the first PlotLabel (i.e.,Sum[Sinc[Pi*(#1 - i*j)], {i, 1, Floor[#1]}] &) into an expression it considers more useful or natural. I don’t want it to do this. I want the PlotLabel for that plot to look like this:

enter image description here

i.e., as though it was written PlotLabel -> "expr". But the other label is already how I want it.

I have experimented with using StringForm but it doesn’t help. How do I do this? Or is it not possible?

One Answer

Table[Plot[{Re[ReleaseHold@f] /. j -> 3,  Im[ReleaseHold@f] /. j -> 3}, {n, 0, 15}, 
  GridLines -> Automatic, 
  PlotRange -> All, ImageSize -> 350, 
  PlotLegends -> {"Real", "Imaginary"}, 
  PlotLabel ->  f], 
{f, {HoldForm@Sum[Sinc[Pi*(n - i*j)], {i, 1, Floor[n]}], 
   HoldForm[(-1 + E^(2*I*Pi*n))/(j*(-1 + E^((2*I*Pi*n)/j)))]}}]

enter image description here

You can replace HoldForm and ReleaseHold with Defer and First, respectively, to get the same result.

As Bob Hanlon suggested in comments, in versions 12.0+ you can use ReImPlot as follows:

 Table[ReImPlot[ReleaseHold[f] /. j -> 3, {n, 0, 15}, 
    GridLines -> Automatic, PlotRange -> All, ImageSize -> 350, 
    PlotLegends -> "ReIm", 
    ReImLabels -> {"Real", "Imaginary"}, 
    ReImStyle -> {ColorData[97][1], {ColorData[97][2], Dashing[{}]}},
    PlotLabel -> f], 
  {f, {HoldForm@Sum[Sinc[Pi*(n - i*j)], {i, 1, Floor[n]}], 
      HoldForm[(-1 + E^(2*I*Pi*n))/(j*(-1 + E^((2*I*Pi*n)/j)))]}}]

enter image description here

Answered by kglr on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP