2

从我的计算中,我得到了一个二维实数数组。我想要对它们做的是将它们绘制为图像,其中数组元素的值转换为颜色图。到目前为止,我使用 PyPlot 包进行这种可视化。使用 Pyplot 这很容易。使用灰度值的示例是

using PyPlot

test = rand(3,3);

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

有没有办法做同样的事情,但使用 PGFPlots 包而不是 PyPlot?我已经尝试使用 Plots.Image 但这不适用于数组而不是函数。有任何想法吗?

4

2 回答 2

3

或者

using Plots; pgfplots()
test = randn(3,3)
heatmap(test, c = :greys)
于 2017-03-17T15:39:50.940 回答
2

不确定是否有此功能,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)

在此处输入图像描述

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

在此处输入图像描述

于 2017-03-17T09:55:57.863 回答