Reputation: 53
From my calculations I obtain a 2D array of real numbers. What i want to do with them is to plot them as an image where the values of the array's elements translate into a colormap. Till now I used the package PyPlot for this kind of visualization. With Pyplot it was pretty easy. An example using gray values would be
using PyPlot
test = rand(3,3);
PyPlot.gray()
imshow(test,interpolation="none")
colorbar()
Is there a way to do the same but with the PGFPlots package instead of PyPlot? I have already tried to use Plots.Image but that did not work with an array instead of a function. Any ideas?
Upvotes: 3
Views: 4910
Reputation: 8044
Or
using Plots; pgfplots()
test = randn(3,3)
heatmap(test, c = :greys)
Upvotes: 5
Reputation: 5073
Not sure if there's a function for this in PGFPlots
but you can hack you way around it, by creating a new function:
function plot_matrix(my_matrix)
n,m = collect(size(my_matrix)) .+ 1 .- 1e-10
f(x,y) = my_matrix[Int(floor(x)), Int(floor(y))]
Plots.Image(f, (1, m), (1, n))
end
This gives you the following results:
test = rand(3,3);
plot_matrix(test)
test2 = rand(15, 15);
plot_matrix(test2)
Upvotes: 2