Skip to content

contour for cyclic functions #20548

Closed
Closed
@nschloe

Description

@nschloe

I tried to get a contour plot of the complex angles of a particular function, but always got one level too many around zeros and infinities. Consider the following MWE which is supposed to plot the contour line for pi / 4 only. It plots pi / 4 alright, but also pi.

import numpy as np
import matplotlib.pyplot as plt

xmin, xmax = -3.0, 3.0
ymin, ymax = -3.0, 3.0
nx, ny = 500, 500

x = np.linspace(xmin, xmax, nx)
y = np.linspace(ymin, ymax, ny)
X, Y = np.meshgrid(x, y)
fZ = np.angle(X + 1j * Y)

plt.contour(X, Y, fZ, levels=[0.25 * np.pi], colors="k")
plt.gca().set_aspect("equal")
plt.show()

screenshot

This is with mpl 3.4.2.

Edit: A very similar report is on stackoverflow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions