Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot imagesc style heatmap with colorbar in julia

Tags:

julia

Here is what I tried.

-- Winston package: gives numerous errors saying "syntax deprecated" when trying to install or use. I tried doing Pkg.update() but this doesn't rid me of the errors. Despite the errors however Winston WILL plot a heatmap using the imagesc function just like matlab would... great ! but Winston does not have colorbars (?) :(

-- Plotly package: also gives numerous errors saying "syntax deprecated" when trying to install or use. I tried doing Pkg.update() but this doesn't rid me of the errors. Plotly shows in its documentation that it has colorbars but I cannot get anything working, presumably because of the deprecated syntax issue.

Would greatly appreciate any suggestions to plot imagesc style heatmaps in JULIA! I do not have access to matlab.

like image 315
Jennie D'Ambroise Avatar asked Oct 22 '15 16:10

Jennie D'Ambroise


2 Answers

PyPlot is a good option for this:

using PyPlot

M = rand(10, 10)
pcolormesh(M)
colorbar()

[pcolor stands for "pseudo-color". Yes, it is a terrible name. And yes, it does come from MATLAB, like many other terrible names...]

There are three different relevant functions: pcolor, pcolormesh and imshow, which have different possibilities; see the Matplotlib documentation, e.g. http://matplotlib.org/examples/pylab_examples/pcolor_demo.html (Note that the syntax in Julia can be slightly different.)

The Plots.jl package (https://github.com/tbreloff/Plots.jl) has a heatmap function that works with several different backends. It seems to me that this is the future of plotting in Julia, since you don't have to learn the intricacies of the different packages.

EDIT: Colour bars are indeed implemented in Plots.jl! See this issue: https://github.com/tbreloff/Plots.jl/issues/52

like image 153
David P. Sanders Avatar answered Sep 28 '22 17:09

David P. Sanders


You can try the Vega.jl package. I recently built a stub of a heatmap functionality. The example works with julia 0.4+, but if you have any problems, please file an issue. I update the package pretty frequently.

http://johnmyleswhite.github.io/Vega.jl/heatmap.html

Pkg.add("Vega")
using Vega

x = Array(Int, 900)
y = Array(Int, 900)
color = Array(Float64, 900)

t = 0
for i in 1:30
    for j in 1:30
        t += 1
        x[t] = i
        y[t] = j
        color[t] = rand()
    end
end

hm = heatmap(x = x, y = y, color = color)
like image 23
Randy Zwitch Avatar answered Sep 28 '22 16:09

Randy Zwitch