0
$\begingroup$

Consider the code

h[x_, y_, n_] := x^2 + (y - (x^2)^(1/n))^2
g[u_] := ContourPlot[h[x, y, u] == 1, {x, -1, 1}, {y, -1, 2}, 
  PlotLabel -> StandardForm[h[x, y, u]] == 1]
g[3.1]

which gives

enter image description here

I would like 1/3.1 to be displayed in the PlotLabel instead of the evaluated value 0.322581. I know about HoldForm but how do I apply it only to that bit of the expression.

$\endgroup$
  • $\begingroup$ Why not to simply write it as PlotLabel -> StandardForm[h[x, y, "3.1"]] == 1? In case you do not want to do that since you intend to automate it, you might wrap u by ToString as follows: PlotLabel -> StandardForm[h[x, y, ToString[u]]] == 1. $\endgroup$ – Alexei Boulbitch Feb 1 at 10:55
2
$\begingroup$

You can just wrap HoldForm around u in the plot label to prevent the fraction from being evaluated:

h[x_, y_, n_] := x^2 + (y - (x^2)^(1/n))^2
g[u_] := ContourPlot[h[x, y, u] == 1, {x, -1, 1}, {y, -1, 2}, 
  PlotLabel -> StandardForm[h[x, y, HoldForm[u]]] == 1]
g[3.1]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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