# ContourPlot for a certain value

Consider this example:

f[x_] := -I*2*x + 3*x^2


which is a complex function defined on a complex plane $$x=x_r+ix_i$$

It is convenient to plot the contour of its real part Re[f] with

ListContourPlot[Re[Table[ComplexExpand[f[xr + I*xi]], {xr, 0, 0.2, 0.01}, {xi, -0.05,
0.05, 0.001}]]]


But sometimes we want to only show the contour for a certain value with a legend for the specific value. For example, how can I only plot the contour for Re[f]=0 with a legend for it?

I naively tried as follows, but it didn't work.

ListContourPlot[Re[Table[ComplexExpand[f[xr + I*xi]], {xr, 0, 0.2, 0.01}, {xi, -0.05,
0.05, 0.001}]] == 0]


Thank you for any help.

• How about ContourPlot[ Re[ComplexExpand[f[xr + I*xi]]] == 0, {xr, 0, 0.2}, {xi, -0.05, 0.05}] – chris Jul 5 '20 at 11:42
• @Chris, it can do this, but for some cases when we do not have an analytical function $f$, it is expected that we can plot with ListContourPlot. – user55777 Jul 5 '20 at 11:57

## 2 Answers

This should work

  ff = Re[Table[{xr, xi, ComplexExpand[f[xr + I*xi]]}, {xr, 0, 0.2,
0.01}, {xi, -0.05, 0.05, 0.001}]] // Flatten[#, 1] & //Interpolation Then

  ContourPlot[ff[xr, xi] == 0, {xr, 0, 0.2}, {xi, -0.05, 0.05}] As requested by OP, 'ff' could be written as

   ff = Interpolation [Flatten[Re[Table[{xr, xi, ComplexExpand[f[xr +I*xi]]},
{xr, 0, 0.2,  0.01},
{xi, -0.05, 0.05, 0.001}]], 1]]

• thanks! It works. You created a pure function. Well, could you make it without the postfix form using //Interpolation if it is possible? – user55777 Jul 5 '20 at 13:09
f[x_] := -I*2*x + 3*x^2


Since you are taking the real part, ComplexExpand is not necessary. To get a specific contour, just specify the contour.

ListContourPlot[
Table[{xr, xi, Re@f[xr + I*xi]},
{xr, 0, 0.2, 0.01}, {xi, -0.05, 0.05, 0.001}] //
Flatten[#, 1] &,
Contours -> {{0}},
ContourShading -> None] • your comment and method are useful as well. But I cannot accept both. I accepted chris' answer because that solved my problem earlier. Sorry about that. – user55777 Jul 5 '20 at 14:32
• @user55777 you could still upvote this answer? his answer is better since it doesn't rely on unnecessary interpolation. – chris Jul 5 '20 at 15:35