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))) & }}
]
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:
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?
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)))]}}]
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)))]}}]
Answered by kglr on February 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP