0

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.

frapadingue
  • 103
  • 2
  • 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. – Alexei Boulbitch Feb 01 '19 at 10:55

1 Answers1

2

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

Sjoerd Smit
  • 23,370
  • 46
  • 75