-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
[FR] Interpolation does not work for the heatmap in Plots.jl #2857
Comments
Oooh! I was just running into this issue. I am wondering if there is a "canonical" workaround for it or something of the like :) In particular, one approach is to use the interpolation from Is there an alternative? If so, that would be awesome! (This might also be a GR backend thing, though I'm not 100% sure.) Thanks again for all of your great work, Plots.jl team! Love this package :) |
Hi, I found this issue. Of course, one possible workaround is to interpolate and plot ;-)
I'd like to think about how to incorporate this into Plots.jl, but the package is too large, and I can't find a way to start a PR. Any help would be appreciated! |
Thank you mdmass! This is quite a feasible approach, but I am not sure if a very large factor (which may lead to a huge computational cost) is always needed ensuring that the interpolated heatmap becomes sufficiently smooth. I will try it later on. |
Hey @mdmaas if you are still interested in this send me a pm on either discourse or zulip and we'll find a way to get you started. |
Oh sure. I was about to create a recipe for a dummy type to incorporate this and a few other settings I'd like to have in extra kwargs. Do you think a PR is a better idea? Maybe I could do the recipe first and discuss later how to incorporate it to the main package. |
Sure, prototyping in a recipe is a good idea. |
Hi! Thank you for your response, I had to same issue. But can you generalize to a rectangular random matrix? For example rand(10,15). When I try to interpolate the rectangular random matrix as a heatmap, Plot looks like bullshit :) |
The problem was that So this should work:
|
Hm, it looked better on VSCode before saving the PNG... I guess one could save the file with PDF format... |
I've been playing around with this a little bit... I guess Plots.jl should support both interpolated heatmaps with given vectors The problem I found with using given I guess we could rely on DataInterpolations for 1D interp, and build a simple 2d interpolation routine based on it. Does this seem right to you @BeastyBlacksmith? I guess if this were to be incoporated into Plots.jl you would need an extra dependecy somewhere. Anyway, let me know what you think. |
I'm prototyping a recipe here: pcolor. Given that both Matlab and Python have "pcolor" which is an alias for heatmap, I thought it was a good idea to use that name. So far only linear interpolation is implemented (which looks really bad on random data), and will implement 2d cubic splines shortly. This might eventually get merged into Plots.jl if the mantainers judge it is convenient, but for the meantime the idea would be to have this available:
|
You might want to have a look at https://github.com/kbarbary/Dierckx.jl |
There, it's done in the pcolor repo One issue I couldn't figure out is why Another nice thing to have would be access to the figure resolution to automatically set the |
Isn't that given by the sizes of |
Oh thanks, I finally figured I could get the figure size with:
So I think it's best to just interpolate to a number of points equal to the resolution size (600x400 by default) and remove the oversampling_factor option. |
This now works to full resolution even when you change it with:
which is nice. The only thing I haven't figured out how to fix is that |
Note that that is the size of the whole figure, not just the plotarea, including axis, labels, more subplots if this is a layout, etc. |
Hi! So I went back to this issue. I got around the first problem I had, with So, it's working now. I also also had to rename the package to
This one I couldn't fix it. I believe that when the plot recipe gets called it doesn't have access to the final layout information. Given that the interpolation library is fast enough, I don't believe this to be much of an issue. Anyway, do you think this could be merged into Plots.jl somehow (maybe adding the extra flag to heatmap directly?), or prefer this as a separate package? Now we have package extensions, so it could be an option, too. |
We can definetely integrate this into plots. I imagine the interface being a new keyword Line 375 in ec4b7a4
|
I'll get a PR started, then, as soon as I have some time for this. |
I wish to draw a heatmap for a stress field, and a linear interpolation is preferred (such like the "shading interp" in Matlab) in order to present a smooth distribution. After searching around, I haven't found a helpful answer.
I noticed an earlier issue, where the interpolation is involved in the heatmap automatically.
But unfortunately, I cannot produce the result by using the same code:
z = reshape(1:25,5,5)
heatmap(z)
Instead, the result is as below:
I have tried
heatmap(z, interpolation = true)
heatmap(z, interpolation = :linear)
and so on, but none of them works.
So, can anyone please tell me how to draw a heatmap with interpolation? Thank you!
Version information:
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 6
The text was updated successfully, but these errors were encountered: