Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ENH]: contour/tricontour: return values along contour #21309

Closed
@nschloe

Description

@nschloe

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()

screenshot

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.

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp