我在MATLAB中设计了一个可视化模拟,如下所示:
如何使plot
和imagesc
使用相同的颜色?我希望能够查看绘图中的图例,并将该行与左侧可视化中的相同颜色进行比较。
MWE:
field=randi(7,10);
distribution=rand(100,7);
h=figure(1);
set(gcf,'PaperPositionMode','auto')
set(h, 'Position', [500 500 1000 500])
subplot(1,2,1);
imagesc(field);
colormap('copper');
subplot(1,2,2);
plot(distribution);
legend('1','2','3','4','5','6','7')
答案 0 :(得分:3)
很难说明您希望如何排序颜色,但这会将colormap
从默认值更改为copper
。
%// sample data
field=randi(7,10);
distribution=rand(100,7);
h=figure(1);
set(gcf,'PaperPositionMode','auto')
set(h, 'Position', [500 500 1000 500])
subplot(1,2,1);
imagesc(field);
colormap('copper');
colorbar
h=subplot(1,2,2);
set(get(h,'Parent'),'DefaultAxesColorOrder',copper(7)) %// set the ColorOrder for this plot
plot(distribution);
legend('1','2','3','4','5','6','7')