如何将向量(即 1xN 或 Nx1 矩阵)绘制为图像? 我可以毫无问题地绘制 2x2 矩阵,如下所示:
plot '-' matrix with image
1 2
3 4
e
但是,以下两个 2x1 和 1x2 矩阵的示例失败了:
plot '-' matrix with image
1
3
e
plot '-' matrix with image
1 2
e
对于两者,我都收到警告:
Image grid must be at least 4 points (2 x 2).
什么也没有渲染。
是否有另一种方法来绘制 Nx1 或 1xN 矩阵,以便它们呈现类似于 2x2 矩阵?
“使用一行的gnuplot矩阵或调色板”可能与相关部分相关。然而,那里的问题要复杂得多。
这个答案假设 gnuplot 版本 6
有点。绘图
with image
不接受一维数组,但您可以创建一个一维像素图并绘制它。
# Create a 1x4 colormap named M1x4
set palette maxcolors 4
set colormap new M1x4
# Restore palette mapping that will be used for a plot
# Note: maxcolors 0 resets to the default for the current terminal
# cbrange sets the range of values the palette will map to
set palette maxcolors 0
set cbrange [0:512]
# Unfortunately the palette values are not recalculated until something
# is plotted to use them, so make a dummy plot to force the recalcuation.
set table $junk
plot x lc palette
unset table
# Reload the entries in our named colormap with the corresponding
# mappings of data values into the current palette.
array DATA = [ 15, 127, 415, 333 ]
M1x4[1] = palette( DATA[1] )
M1x4[2] = palette( DATA[2] )
M1x4[3] = palette( DATA[3] )
M1x4[4] = palette( DATA[4] )
print M1x4
# Now define a pixmap object to be plotted
set pixmap 1 colormap M1x4 size 4, 1
set pixmap 1 at graph 0.5, graph 0.5
# Plot anything you like; the pixmap object will be part of the plot
# For the purpose of illustration, we choose something that will show
# the palette mapping in the color box.
plot x lc palette
不使用像素图的版本 5 的解决方法
要解决高度和宽度均大于 1 的需求,您可以添加包含 NaN 的虚拟值行。绘制时这些将是透明的
with image
,尽管它们确实会影响缩放:
plot '-' matrix with image
15 127 415 333
NaN NaN NaN NaN
e