# Contour plot of the imaginary portion of a function given the real part is positive

How do I plot the imaginary part of the function while its real part is positive?

For example, for the below code I could have the imaginary part but I am not able to find the positive or negative real part of the function.

ContourPlot[{Im[x + I*y - Log[x + I*y]]}, {x, -6, 8}, {y, -6, 6}, Contours -> {0}]

• ContourPlot[Im[x + I y - Log[x + I y]], {x, -6, 8}, {y, -6, 6}, RegionFunction -> Function[{x, y}, Re[x + I y - Log[x + I y]] > 0]]
– user484
Commented Jan 13, 2016 at 21:58
• Hi Raul, for this command, are we first picking up the values of x and y, that satisfies the Re()>0, and then it plots the imaginary part? If so, If I want to add one more function in to this plot, How could I do it? Thank you
– Jane
Commented Jan 14, 2016 at 10:15
• @Rahul, in this case, say I also want to plot this function x + I y - 4*Log[x + I *y] - 4 + 4*Log[4], how could I plot both in the same plot? Thank you
– Jane
Commented Jan 14, 2016 at 10:35
• In that case you have to think about what you want drawn in the region where the real part of both functions is positive.
– user484
Commented Jan 14, 2016 at 19:25
• There are things to do after your question is answered. It's a good idea to stay vigilant for some time, better approaches may come later improving over previous replies. Experienced users may point alternatives, caveats or limitations. New users should test answers before voting and wait 24 hours before accepting the best one. Participation is essential for the site, please come back to do your part tomorrow Commented Jan 20, 2016 at 16:21

I'm posting this to put Rahul's answer, given in a comment to the question, on record.

ContourPlot[Im[x + I y - Log[x + I y]], {x, -6, 8}, {y, -6, 6},
Contours -> {0},
RegionFunction -> Function[{x, y}, Re[x + I y - Log[x + I y]] > 0]]


The yellow regions are positive and the blue regions are negative.

The plot can be much cleaner if a nicer ColorFunction is used and the cutoff at Re[function]==0 is not so abrupt:

ContourPlot[Im[x + I y - Log[x + I y]], {x, -2, 6}, {y, -6, 6},
Contours -> 16, (* 16 contours seemed like a good number *)
BoundaryStyle -> {Thick, Gray}, (* this adds a nice line at the edge of the region *)
RegionFunction -> Function[{x, y}, Re[x + I y - Log[x + I y]] > 0],
ColorFunction -> "TemperatureMap" (* cool colors are negative, warm - positive *)
]


There's still an artifact at y==0 && x<0. This is to be expected, Log[z] has a branch-cut on the negative real half-line.

ContourPlot[
If[Re[x + I*y - Log[x + I*y]] > 0, Im[x + I*y - Log[x + I*y]], 0],
{x, -6, 8}, {y, -6, 6},
PlotPoints -> 100,
Contours -> {0}]

• Hi @David, this command works but, there occurs a zigzag line, which I believe is the contour (Re()) picture of the function. Say, our function is x + I y - 4*Log[x + I *y] - 4 + 4*Log[4] , in this case, that zigzag line turns out to be a half infinity sign , which I don't want it to be in the plot. Would you please let me know if I could do something with it? Thank you
– Jane
Commented Jan 14, 2016 at 10:09

You can use Piecewise and set its default to an imaginary number so that nothing is plotted for default values.

ContourPlot[
Piecewise[{{
Im[x + I*y - Log[x + I*y]],
Re[x + I*y - Log[x + I*y]] > 0}}, I],
{x, -6, 8}, {y, -6, 6},
PlotPoints -> 75,
Contours -> 16,
ColorFunction -> "TemperatureMap"]


Or you can restrict the plot to a region

reg = DiscretizeRegion@ImplicitRegion[Re[x + I*y - Log[x + I*y]] > 0,
{{x, -6, 8}, {y, -6, 6}}];

ContourPlot[
Im[x + I*y - Log[x + I*y]],
{x, y} ∈ reg,
Contours -> 16,
PlotPoints -> 75,
ColorFunction -> "TemperatureMap"]


For comparison purposes,

Plot3D[Im[x + I*y - Log[x + I*y]],
{x, y} ∈ reg,
ColorFunction -> Function[{x, y, z},
ColorData["TemperatureMap"][z]]]


Since V 12.1 there are ComplexContourPlot as well as ComplexRegionPlot

ComplexContourPlot[Im[z - Log[z]], {z, -2 - 6 I, 6 + 6 I},
BoundaryStyle -> {Thickness[0.004], GrayLevel[0.5]},
ColorFunction -> "RedBlueTones" ,
Contours -> 16,
PlotLegends -> Automatic,
RegionFunction -> Function[{z}, Re[z - Log[z]] > 0]]


ComplexRegionPlot[
{Re[z - Log[z]] < 0, Im[z - Log[z]] < 0}, {z, -2 - 6 I, 6 + 6 I},
PlotLabels -> {"Re", "Im"}]