2017-03-16 21 views
1

從我的計算中,我獲得了一個實數的二維數組。我想要做的是將它們繪製爲圖像,其中數組元素的值轉換爲色彩映射。到目前爲止,我使用PyPlot軟件包進行這種可視化。用Pyplot很容易。使用灰度值的一個例子是Julia:使用pgfplots包將矩陣繪製爲圖像

using PyPlot 

test = rand(3,3); 

PyPlot.gray() 
imshow(test,interpolation="none") 
colorbar() 

有沒有辦法做同樣的,但與PGFPlots包,而不是PyPlot? 我已經嘗試過使用Plots.Image,但沒有使用數組而不是函數。有任何想法嗎?

回答

0

不知道是否有此功能在PGFPlots但你可以砍你的方式圍繞它,通過創建一個新的功能:

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 

這給你以下結果:

test = rand(3,3); 
plot_matrix(test) 

enter image description here

test2 = rand(15, 15); 
plot_matrix(test2) 

enter image description here

2

using Plots; pgfplots() 
test = randn(3,3) 
heatmap(test, c = :greys)