# Using function definition in plot caption?

**URL:** <https://community.wolfram.com/t/using-function-definition-in-plot-caption/19161>\
**Category:** Questions\
**Tags:** graphics-and-visualization\
**Created:** [November 23, 2021, 9:55am UTC](https://community.wolfram.com/t/using-function-definition-in-plot-caption/19161 "2021-11-23T09:55:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakobscholbach](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jakobscholbach](https://community.wolfram.com/u/jakobscholbach)\
**Post date:** [November 23, 2021, 9:55am UTC](https://community.wolfram.com/t/using-function-definition-in-plot-caption/19161/1 "2021-11-23T09:55:13Z")

</div>

Suppose I have defined `f[z_]=z^2-4`. Then I want to create a parametric plot for the function f (which I am able to do), that has the caption “f(z) = z²-4”, i.e., I want to join the string "f(z) = " with the parsed output how the function f was defined before. How can I do that?

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [November 23, 2021, 2:50pm UTC](https://community.wolfram.com/t/using-function-definition-in-plot-caption/19161/2 "2021-11-23T14:50:57Z")

</div>

Hi Jakob,

Here is one way

```
ClearAll@f    
f[z_] := z^2 - 4;

Plot[f[x], {x, 0, 4},
 PlotLabel -> Row[{HoldForm@TraditionalForm@f[x], " = ", TraditionalForm@f[x]}]]

```

 ![3942plot.png](https://global.discourse-cdn.com/wolfram/original/2X/7/742c05f14852f8a2a63be545ae6756585e449702.png)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [November 26, 2021, 7:56pm UTC](https://community.wolfram.com/t/using-function-definition-in-plot-caption/19161/3 "2021-11-26T19:56:01Z")

</div>

This can be encapsulated in a function to make it easier to use

```
ClearAll@functionLabel;
SetAttributes[functionLabel, HoldAll];
functionLabel[function_] := Row[{HoldForm@TraditionalForm@function, " = ", 
 TraditionalForm@function}]

z[x_, y_] := Sin[x]*Cos[y]
Plot3D[z[x, y], {x, 0, Pi}, {y, 0, Pi}, PlotLabel -> functionLabel[z[x, y]]]

```

 ![5672plot.png](https://global.discourse-cdn.com/wolfram/original/2X/5/583890fa39b6b50e32345153466537aa21a614d7.png)

The [`MaTeX`](https://github.com/szhorvat/MaTeX) paclet can be used to generate typeset labels. e.g.

```
f[x_] := Evaluate@Integrate[Sin[t], {t, 0, x}]
Plot[f[x], {x, 0, Pi},
 PlotLabel -> MaTeX["f(\\text{x})\\text{ =}\\int_0^x \\sin (t) \\, dt", FontSize -> 16],
 PlotTheme -> "Scientific",
 PlotLabels -> "Expressions"]

```

 ![1982plot.png](https://global.discourse-cdn.com/wolfram/original/2X/8/84f9516a2724d354103938cad129bd34ee05e6c4.png)
