Jennie D'Ambroise
Jennie D'Ambroise

Reputation: 111

How to plot imagesc style heatmap with colorbar in 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.

Upvotes: 8

Views: 7124

Answers (2)

David P. Sanders
David P. Sanders

Reputation: 5325

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

Upvotes: 8

Randy Zwitch
Randy Zwitch

Reputation: 2064

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)

Upvotes: 5

Related Questions