在MATLAB图例的图例中设置线颜色? [英] Setting line colors in legend of MATLAB plot?

查看:2116
本文介绍了在MATLAB图例的图例中设置线颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用BNT的plotgauss2d函数来显示当在网络中的其他地方观察到证据时,2D高斯节点的响应如何变化。

I am using the plotgauss2d function of BNT to visualize how the response of a 2D Gaussian node changes when evidence is observed elsewhere in the net.

eng = jtree_inf_engine(bnet);
evidence = cell(1, 2)
eng = enter_evidence(eng, evidence);
marginals = marginal_nodes(eng, 1); p_1 = marginals.T
marginals = marginal_nodes(eng, 2); p_2 = marginals.T
marginals
clf; plotgauss2d(marginals.mu, marginals.Sigma);
hold all;
evidence{1} = 1;
marginals = marginal_nodes(enter_evidence(eng, evidence), 2);
p = plotgauss2d(marginals.mu, marginals.Sigma);
set(p, 'Color', 'green');
evidence{1} = 2;
marginals = marginal_nodes(enter_evidence(eng, evidence), 2);
p = plotgauss2d(marginals.mu, marginals.Sigma);
set(p, 'Color', 'red');
legend({'Unknown', 'Class 1', 'Class 2'});
hold off;

正如你所看到的,图例并没有拾取我手动设置的改变的图表颜色。 (

As you can see, the legend is not picking up the changed plot colors I had to manually set. (Sadly plotgauss2d does not cycle through colors automatically as you might wish.)

有没有办法设置图例中使用的线条颜色?

Is there a way to set the line colors used in the legend too?

推荐答案

PLOTGAUSS2D 函数分别返回与短轴,长轴和椭圆对应的三个句柄的向量。下面是一个例子,如何存储句柄,并在末尾调用LEGEND:

The PLOTGAUSS2D function returns a vector of three handles corresponding to minor axis, major axis, and ellipse respectively. So here is an example how to store the handles and call LEGEND at the end:

figure, hold on
h = zeros(3,3);
h(:,1) = plotgauss2d(rand(2,1), [1 0.5; 0.5 2]);
h(:,2) = plotgauss2d(rand(2,1), [2 -0.5; -0.5 1]);
h(:,3) = plotgauss2d(rand(2,1), [1 0; 0 2]);
hold off
set(h(:,1), 'Color','r')
set(h(:,2), 'Color','g')
set(h(:,3), 'Color','c')
legend(h(1,:), {'1','2','3'})

这篇关于在MATLAB图例的图例中设置线颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆