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?
Legend does pick up line colors, styles, markers, and so on.
You must have at least three
plot
s in eachplotgauss2d plot
. As such, yourlegend
command is applying thelegend
to the first threeplot
s, all from the first call toplotgauss2d
.Skipping some of your code, you can make your legend right by doing this:
Now you are causing
legend
to apply thelegend
to oneplot
from each of yourplotgauss2d
calls.Also, I would suggest adding a line at the end:
I think you will like what it does.
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: