matlab用Java绘图_使用Matlab自定义绘图

以下是我的建议:

% orginal data:

x = 1:4;

y1 = 'abac';

y2 = 'aabc';

y3 = 'caaa';

y4 = 'abca';

Y = [y1;y2;y3;y4];

% convert to numeric:

y = Y-'a'+1;

y = rot90(y,3);

% create an "image" of the data:

res = 10;

ymesh = nan(size(y,1)*res,(size(y,2)+1)*res);

for ii = 1:size(y,1)

for jj = 1:size(y,2)

ymesh(res*(jj-1)+1:res*jj,res*ii) = y(ii,jj);

end

end

% set the boundries between y categories

ymesh(res:res:size(ymesh,1)-res,:) = 4;

% plotting:

abcCol = [1 1 1;0 0.7 0;0.8 0 0;1 0.8 0;0 0 0];

xtic = res:res:length(ymesh)-1;

xticlable = num2str((1:size(y,1)).');

ytic = res/2:res:size(ymesh,1)-res/2;

yticlable = {'4^{th} run','3^{ed} run','2^{nd} run','1^{st} run'};

f = figure('Colormap',abcCol);

imagesc(ymesh)

set(gca,'Parent',f,'CLim',[0 4],...

'YTickLabel',yticlable,'YTick',ytic,...

'XTickLabel',xticlable,'XTick',xtic)

% add the legend on anoother 'fake' axes

legax = axes('Parent',f);

p = plot(nan(2,3),'Linewidth',3);

set(p,{'Color'},mat2cell(abcCol(2:end-1,:),[1 1 1].',3));

legend (unique(Y))

axis off

这将创建这个:

5cd5f3d5-0971-489d-b960-c643e3519db9.png

上面的代码非常特定于您的问题,但可以轻松推广 . 主要思想是创建数据的“图像”,并使用栅格技术绘制它,而不是分别绘制每一行 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值