Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Problem
(A follow-up on#20548.)
The purpose of contour and tricontour is to draw contour lines along given levels. The algorithm tries to close the contour loops, but sometimes that's not possible or useful. Example:
importnumpyasnpimportmatplotlib.pyplotaspltxmin,xmax=-3.0,3.0ymin,ymax=-3.0,3.0nx,ny=500,500deff(z):returnnp.angle(z)x=np.linspace(xmin,xmax,nx)y=np.linspace(ymin,ymax,ny)X,Y=np.meshgrid(x,y)fZ=f(X+1j*Y)c=plt.contour(X,Y,fZ,levels=[0.7853981633974483],colors="k")plt.show()
The left "arm" of the contour is wrong. Let's verify this by computing the values:
forallseginc.allsegs:forseginallseg:x,y=seg.Tz=x+1j*yprint(f(z))
[3.141091333.141089313.141087283.141085233.141083163.14108107# ...3.133444683.132876553.132223263.13146413.130571093.12950543.128211583.126607613.124566833.121882723.11819433.112808683.104206373.088290913.049016182.81984210.785398160.785398160.785398160.785398160.785398160.785398160.785398160.785398160.785398160.785398160.785398160.785398160.785398160.78539816# ....785398160.785398160.785398160.785398160.785398160.785398160.785398160.78539816]
Note that the specified level is0.7853981633974483
, so the first half is completely off.A previous comment suggests that the contouring algorithm is right, though.
To fix this, I manually set the corresponding segments tonp.nan
which prevents plotting. However, this doesnot work for tricontour as I don't have a functionf()
that I can evaluate at the segments. The contouring algorithm itself must compute the values somewhere, so my suggestion would be to expose those values to the user.