Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contour plots #36

Closed
tbreloff opened this issue Sep 29, 2015 · 9 comments
Closed

Contour plots #36

tbreloff opened this issue Sep 29, 2015 · 9 comments

Comments

@tbreloff
Copy link
Member

Can maybe depend on https://github.com/tlycken/Contour.jl

@tbreloff
Copy link
Member Author

tbreloff commented Oct 7, 2015

Contour doesn't have exactly what I want, so I'll do it myself, and maybe submit a PR at some point. I'm sure I'm not the first person to come up with an algorithm like this, but here's the back-of-the-napkin idea that I'm thinking through:

  • Bucket (x,y,z) vertices into (x,y) squares
  • Pick a "center vertex" (x,y,z) in each square
  • Estimate the z-value of each corner given nearby points
  • Create 4 triangles from the square corners and center vertex
  • Each triangle will cross the "contour surface", or not. If it crosses, the contour line will pass through exactly 2 edges (or vertex if it lies exactly on the surface). Interpolate/store the intersection vertex for each edge.
  • Now, starting at the borders, loop through edges looking for an intersection point. When found, add to contour line, then search adjacent edges for intersection. Stop at border or if we come to an intersection we've already added.
  • Repeat this search until all edges have been visited

Repeat this process for each contour level needed.

I'll likely need to create some types representing vertices, edges, squares, triangles, contours, etc. I should try to use https://github.com/JuliaGeometry/GeometricalPredicates.jl

@tbreloff
Copy link
Member Author

tbreloff commented Oct 8, 2015

Looking at using Delaunay triangulation which is implemented in https://github.com/JuliaGeometry/VoronoiDelaunay.jl, which would replace the need for the grid and triangle creation steps, as well as reducing the effort to estimate z-values.

I think it's probably a good idea to smooth the z-values somehow... this could be parameterized.

@tbreloff
Copy link
Member Author

Basics are done. For now, I'm just allowing the inputs and passing through to a backend function. (Geom.contour in Gadfly/Immerse, contour/contourf in PyPlot). I currently accept a function mapping (x,y) to a z-value, and z-matrices (similar to Gadfly's interface). In the future I'll expand the allowed inputs to arbitrary points in 3D space, so I'll leave this open until I have more native support for estimating surfaces and contours and generically plotting them. Here's some examples:

Gadfly/Immerse:

tmp

PyPlot:

tmp

@tbreloff tbreloff mentioned this issue Oct 26, 2015
4 tasks
@Evizero
Copy link
Member

Evizero commented Nov 21, 2015

I think there is a bug with the Gadfly backend. I get different results for pyplot and gadfly, where I know for a fact that the minimum in the gadfly plot is wrong

gadfly()
p_cost = plot(-4:.1:4, -4:.1:4, (θ1, θ2) -> cost(X, [θ1, θ2], y), nlevels = 100)

gadfly

pyplot()
p_cost = plot(-4:.1:4, -4:.1:4, (θ1, θ2) -> cost(X, [θ1, θ2], y), nlevels = 100)

pyplot

@Evizero
Copy link
Member

Evizero commented Nov 21, 2015

actually there is a lot more going on. Both are wrong sometimes. Look at these gadfly plots that have the same minimum but are plotted with different ranges. I am not sure what's going on.

gadfly1

gadfly2

@tbreloff
Copy link
Member Author

Can you post a full example so I can run it? (Or make a gist) does this happen if you do contours directly through pyplot/gadfly?

On Nov 21, 2015, at 5:52 AM, Christof Stocker [email protected] wrote:

I think there is a bug with the Gadfly backend. I get different results for pyplot and gadfly, where I know for a fact that the minimum in the gadfly plot is wrong

gadfly()
p_cost = plot(-4:.1:4, -4:.1:4, (θ1, θ2) -> cost(X, [θ1, θ2], y), nlevels = 100)

pyplot()
p_cost = plot(-4:.1:4, -4:.1:4, (θ1, θ2) -> cost(X, [θ1, θ2], y), nlevels = 100)


Reply to this email directly or view it on GitHub.

@Evizero
Copy link
Member

Evizero commented Nov 21, 2015

Sure, I'll look into it

@Evizero
Copy link
Member

Evizero commented Nov 21, 2015

Ah, I confused this issue with the closed one. So sorry that I opened a new one for this. see #80

@tbreloff
Copy link
Member Author

Similar in spirit to what I wanted to do with this issue... I added support of pyplot's tri-surface to be able to plot a surface given only x/y/z as vectors (i.e. no need to build the full grid of values... way more memory-friendly for many problems):

tmp

t-bltg pushed a commit that referenced this issue Oct 6, 2022
t-bltg pushed a commit that referenced this issue Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants