"PlotLabel" สำหรับพล็อตใน "ตาราง"
Sep 08 2020
ฉันมีTableสองแปลงที่มีให้โดย
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))) & }}
]
อย่างที่คุณเห็น Mathematica ได้เขียนคำแรกPlotLabel(กล่าวคือSum[Sinc[Pi*(#1 - i*j)], {i, 1, Floor[#1]}] &) ลงในนิพจน์ที่เห็นว่ามีประโยชน์หรือเป็นธรรมชาติ ฉันไม่อยากให้มันทำแบบนี้ ฉันต้องการPlotLabelให้พล็อตนั้นมีลักษณะดังนี้:
PlotLabel -> "expr"คือเหมือนกับว่ามันถูกเขียนขึ้น แต่ป้ายอื่น ๆ เป็นไปแล้วว่าฉันต้องการอย่างไร
ฉันได้ทดลองใช้StringFormแต่ไม่ได้ผล ฉันต้องทำอย่างไร หรือเป็นไปไม่ได้?
คำตอบ
6 kglr Sep 08 2020 at 19:04
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)))]}}]
คุณสามารถแทนที่HoldFormและReleaseHoldด้วยDeferและFirstตามลำดับเพื่อให้ได้ผลลัพธ์เดียวกัน
ตามที่ Bob Hanlon แนะนำในความคิดเห็นในเวอร์ชัน 12.0+ คุณสามารถใช้ได้ReImPlotดังต่อไปนี้:
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)))]}}]