The legend does display line colors, styles, markers, etc.
Each plotgauss2d plot must have at least three plot . So your legend command applies legend to the first three plot s, from the first call to plotgauss2d .
By skipping part of your code, you can make your legend by doing the following:
p = plotgauss2d(marginals.mu, marginals.Sigma); h = p(1); hold all; evidence{1} = 1; marginals = marginal_nodes(enter_evidence(eng, evidence), 2); p = plotgauss2d(marginals.mu, marginals.Sigma); h(end+1) = p(1); set(p, 'Color', 'green'); evidence{1} = 2; marginals = marginal_nodes(enter_evidence(eng, evidence), 2); p = plotgauss2d(marginals.mu, marginals.Sigma); h(end+1) = p(1); set(p, 'Color', 'red'); legend(h,{'Unknown', 'Class 1', 'Class 2'});
Now you call legend to apply legend to one plot from each of your calls to plotgauss2d .
In addition, I would suggest adding a line at the end:
axis equal;
I think you will like what he does.
source share