Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在matlab中,在同一个图形上绘制热图和线图_Matlab - Fatal编程技术网

在matlab中,在同一个图形上绘制热图和线图

在matlab中,在同一个图形上绘制热图和线图,matlab,Matlab,在Matlab2014b中,我想制作一个热图,然后使用右y轴覆盖一个线图。比如说 colormap bone data = rand(6); imagesc(data) ax = gca; ax.XTick = [1 2 3 4 5 6]; ax.YTick = [1 2 3 4 5 6]; hold on 现在绘制一条直线,但使用右y轴,因为该轴具有负值: x2 = [1 2 3 4 5 6]; y2 = [-0.0001 -0.0997 -0.1997 -0.2995

在Matlab2014b中,我想制作一个热图,然后使用右y轴覆盖一个线图。比如说

colormap bone
data = rand(6);
imagesc(data)
ax = gca; 
ax.XTick = [1 2 3 4 5 6];
ax.YTick = [1 2 3 4 5 6];

hold on
现在绘制一条直线,但使用右y轴,因为该轴具有负值:

x2 = [1 2 3 4 5 6];
y2 = [-0.0001   -0.0997   -0.1997   -0.2995   -0.3994   -0.4995];
plot(x2,y2,'r')

您可以更改第一个绘图由
NaNs
组成的位置

代码如下:

hold on

colormap bone
data = rand(6);
imagesc(data)
ax = gca; 
yT = ax.YTick;

x2 = [1 2 3 4 5 6];
y2 = [-0.0001   -0.0997   -0.1997   -0.2995   -0.3994   -0.4995];
[ax, ~, h] = plotyy(yT*NaN, yT, x2,y2);

ax(1).YLim = [yT(1)-0.5 yT(end)+0.5];
ax(1).YTick = yT;
ax(1).YColor = [0 0 0];
set(h, 'Color', 'r');
ax(2).YColor = [1 0 0];
ax(2).YTick = -0.5:0.1:0;
结果是:


最好,

如何定义“右y轴”?我不明白你想得到什么,你能画一幅画吗?@Ratbert如中所示,在情节的右侧