-
Notifications
You must be signed in to change notification settings - Fork 251
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
Draw contours for scatterplots #955
Comments
Could you give a minimal example (with a plot preferably) of what you would like to have? |
shows pretty well what would be useful. This is about as close as I could get. I used the following code to bin the data: function contourify(x::Symbol, y::Symbol, xmin::Int, xmax::Int, ymin::Int, ymax::Int, xres::Int, yres::Int)
A = zeros(Int, (xres, yres))
xdata = TABLE1[x] .+ (0-xmin)
ydata = TABLE1[y] .+ (0-ymin)
xdelta = (xmax - xmin) / xres
ydelta = (ymax - ymin) / yres
for i in 1:length(xdata)
A[ (xdata[i] / xdelta |> ceil |> Int),
(ydata[i] / ydelta |> ceil |> Int) ] += 1
end
A, [xmin + xdelta * i for i in 0:xres-1], [ymin + ydelta * i for i in 0:yres-1]
end I'm sure there are better ways, but I just wanted a quick and dirty solution as I'm not using a huge dataset. There's probably an even better way, which would be something like finding the mean of all points, then drawing a curve around the closes n points to the centre, then the closest n+10 or whatever points. I know that what's causing the problem with mine (tiny contour lines centred around the middle) is a more exponential falloff, but there should be some good way of dealing with that, I assume. |
i've got some code to do this. will post tomorrow. |
the "better way" is to use
would be great to see this built-in to Gadfly. let me know how i can help with that. |
Awesome, thank you! Yes, I agree this would make a good addition. Options for having linear, logarithmic, exponential, etc. density falloffs would be nice as well. |
Great work @bjarthur! Do you have any thoughts on what kind of interface might be best? It seems a bit specific right now. |
perhaps the aesthetics of if that makes sense, i can draft a PR. |
What about doing something like what ggplot does?
from http://docs.ggplot2.org/current/geom_contour.html So then you can |
sounds good. will try to get to this next week. |
Example code courtesy of @bjarthur here: http://gadflyjl.org/latest/lib/geoms/geom_density2d.html#Geom.density2d-1 |
I'm using Geom.contour to draw contour lines on top of a scatter plot. Right now I'm creating my own 2d bins and using this, but this also has the disadvantage of not drawing a contour line around the outer portions of the points. This would be a really nice feature to have, though I don't know how hard it might be to implement efficiently.
The text was updated successfully, but these errors were encountered: