-
Notifications
You must be signed in to change notification settings - Fork 252
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? #293
Comments
I do have I don't have contour plots but would really love to add that. Gadfly has been in an effective feature freeze lately, just because I've been focusing on overhauling its underlying architecture. When that's complete, I'll try to make this a high priority. It might be a few weeks though. |
That sounds terrific =) I'm no expert, and like everyone else I have limited time on my hands to work on this kind of stuff, but if I can I'd love to help out in some way. |
I just tried out
|
I would love contour plots as well. I use PyPlot's contour function extensively in the courses I teach. |
I've been trying to get a marching squares contouring algorithm working for Gadfly. Here is what I've been able to get so far: This is still a complete patch job. It essentially creates a new Geom.line layer for each isoline it finds. I have not been able to get the color bar to show. Maybe this is because I've been assigning line color through the default_color option in Themes? I will try to make a cleaner version once I get a better understanding of how Gadfly works internally. Hope this helps! |
Patch job or not, that looks lovely. |
@darwindarak Lovely indeed! Can I just checkout the contour branch of your fork to use this? What does the API look like? |
Great work @darwindarak! I'd love to help you integrate this into Gadfly. The best way to do so would be to add your marching squares code as a new statistic type, say Let me know if I can help explain anything. |
Thanks for the feedback guys! @tlycken The current contour branch can be used like this. I've only tried the method on a couple of test functions. It would be great if you can help stress test it with more complicated contours. I'm still pretty new at using Julia, so I would really appreciate any comments on the code. @dcjones One of the problems I ran into was the case when there are separate contour lines for the same level. If I specify the same color values for all the contours and plot them on a single layer, then it shows a color bar and looks like As opposed to It it because Geom.line groups the lines based on the color value? I'll try to add the new statistics type this weekend! |
Yeah. Currently the only way to have multiple lines of the same color is with multiple layers. That's come up as an annoyance in the past, so I do need to add a separate mechanism for grouping points into lines. Probably a |
@darwindarak There's still a couple of things that are unclear to me. I figured I'd test it on the application I'm currently working on, but I'm still struggling to figure out exactly how to give the data to your algorithm; mainly, I'm finding it difficult to grasp how to arrange the matrix I know it's not how MATLAB and Python do it, but I think the most intuitive way to do this is to give two 1-dimensional iterable If you want to try it out on my data, you can take a look at this gist - for lack of a better way to upload the data, I put it in a script which defines variables If you want to try it out on my data, you can take a look at this gist - for lack of a better way to upload the data, I put it in a script which defines variables
|
Also, things I'd wish for if/when this is incorporated in Gadfly:
And just because I tried a couple of more things, I finally figured out my problem with the transpose: |
And, finally (I'll stop spamming now): please take a look at darwindarak/Gadfly.jl#1 |
The two dimensional
|
Since Julia is column major, having the first dimension along columns makes the most sense to me (i.e. When discussing this for Grid, both @timholy and @simonbyrne provided good arguments for their stances. |
+1 for |
@dcjones The contour tracing package is coming together and should be ready in a couple of days. However, I'm still having some difficulty implementing |
Great news! The right way to add this is definitely with a |
This is great! Thanks a lot @dcjones! Sorry for dragging this issue on, but is there currently a way to plot contours of a matrix instead of a function? For example, the |
I don't have a lot of experience with contour plots, so by all means let me know if this can be improved on. Case in point, I completely forgot to support plotting matrices. I'll fix that shortly. |
I'm really psyched about this! Would you mind showing a short usage example? @tlycken @dcjones @darwindarak ? Others are requesting this too =) https://groups.google.com/forum/#!topic/julia-users/yVKubPEoUYE |
Sure, the simplest usage is like: plot((x, y) -> x^3 - y^3, -10, 10, -10, 10) You can control the number of contours and the number of samples on each axis with plot((x, y) -> x^3 - y^3, -20, 20, -20, 20, Stat.contour(samples=50, n=100)) As mentioned, I still need to add support for plotting matrices directly. The other thing is there's not a version that will plot multiple functions, as in Reopening so I remember that there's more work to do. |
The method error was my fault. Fixed in 7623c6e. For the rest, others will have to comment. |
Fix contour line ordering issue from #293
How does one plot contours for a matrix (i.e. an already sampled function)? |
Also, I found another issue: when plotting more complicated functions, which have several contour lines for the same level, they are connected by a line that shouldn't be there. It's somewhat non-trivial to define a function that makes this obvious, but I did manage to find an example that illustrates the point: julia> plot((x,y) -> x*exp(-(x-int(x))^2-y^2), -8., 8, -2., 2) I haven't looked into this in any detail - if this is somehow due to the output from |
Darwin added support for plotting contour plots from matrices, using the plot(z=M, Geom.contour) It looks like we have the essential functionality now, is there anything else that's lacking? |
I'll add the documentation tonight! |
@dcjones and @darwindarak, you guys rock my socks! =) I suppose that also means I can get the x and y axes scaled correctly by doing something like |
If you do |
@johansigfrids Which version of Gadfly are you using? |
@tlycken |
@darwindarak |
I haven't tagged a new version since the last few fixes. I'll do that soon, but if you want the changes now you can use |
Ok, it works on the latest master. :) |
Is there a way to add labels directly to the contour lines? Something similar to the output of MATLAB's "contour", described here: http://www.mathworks.com/help/matlab/ref/contour.html The color-coded legend is great for computer screens but might be challenging for print publication. |
There's not currently a way to label the contours directly. That would be very nice to have. |
This doesn't seem to work with layer? I am trying to plot a contour plot, and position a single point onto it. This works plot((x, y) -> sqerror(gen_function(x, y), df), -1, 2, -1, 2, Stat.contour(levels = 1000)) But this does not
Complains that there is no method layer matching Function, Int, Int, Int, Int, ContourStatistics. (just |
That seems to be missing functionality - @darwindarak can probably fix it, but I happen to know he has a lot of other things on his hands at the moment so it may take a while. In the meantime, try plotting a layer built from a matrix rather than from a function:
That works for me. |
You can get that to work for multiple contour plots? It doesn't work for me. |
@weymouth: No, that's true. I can only do it with a single contour layer at a time (and that bugs me too...). |
Sorry to dredge up an old thread, but I wanted to see what's currently possible before I do too much work myself, in case there's been progress that I don't know about. Is it currently possible to:
I plan on supporting all that with Plots... just don't want to duplicate any work if it's already working. cc: @tlycken @darwindarak |
@tbreloff The underlying contour calculations are done by Contour.jl, which currently only supports (rectangularly) gridded data. I see no reason why it shouldn't work with sparse matrices, but it will probably be very inefficient - there are no optimizations in place for it, so the algorithm will index into each location - even the zero ones - at least once. Regarding the other features, I don't think there's any work going on to support them at the moment, but @darwindarak probably knows better; I know I've seen requests for support of layering contours (earlier in this thread, for example) but I don't know if anything has actually happened. Doing the actual plotting of these things is quite some way outside of my comfort zone, and thus I haven't invested any time whatsoever in it. I'm merely curating the Contours.jl package because packaging was a little outside of Darwin's at the time when Contour.jl was created :) |
@tbreloff: I'm pretty sure most of the features you've listed are either not implemented yet or need a much better implementation.
|
Leave the plotting part to me ;) In regards to sparse matrices, I was actually thinking that the missing values would be unknown (not zero), so the dense algorithm wouldn't work. I suppose the question is better phrased then as whether something like sparse NullableArrays would be supported. This is roughly the same problem as "contouring irregular data" though, so I'd probably solve that first and get the NullableArrays solution for free. For filling the contours... I added a new feature yesterday to Plots for custom markers, and I was thinking I could just overlay a bunch of custom polygons with each contour section defining the custom shape of each marker. Then I'd be using I'm open to other ideas, and would love collaboration on a general algorithm to build contours from irregular data. |
If I understand correctly, Gadfly currently focuses on 2D plotting mainly because drawing in 3D is a quite different endeavor. However, there are several types of plots that visualize 3D data on a 2D surface, such as contour plots and color-coded projections like MATLAB's
imagesc
, that I think would constitute a nice addition to the library.Are there any plans on adding functionality for such plots to Gadfly, in the near or distant future?
For contour plots, for example, calculating where to draw the contour lines is quite involved (see e.g. this description for a simple overview - one might want to do something even more sophisticated about edge cases) but once the line segments have been identified it should be straight-forward to hook into the existing back-ends to do the actual drawing of colored lines. I guess one could do similar things to create colored projections à la
imagesc
.The text was updated successfully, but these errors were encountered: