一連のマーカーとプロットなしで関連する文字列を使用して、凡例を個別にプロットする必要があります。誰かがこれのコードを見たことがありますか?
よろしく
以前も同じことをしようとしましたが、うまくいきませんでした。私がやったことは、凡例からいくつかのプロット要素を削除することです。例えば:
h = plot(x,y);
hasbehavior(h,'legend', false);
別の例を次に示します。
ここに私が最終的に思いついたコードがあります: ほとんどすべてのアプリケーションに対して十分な柔軟性があります:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Legend Generator %%%%%%%%%%%%%%%%%%%%%
%% NAME : LEGEND_GENERATOR.m
%% FUNCTION : Generates a single plot for arbitrary legend
%% INPUTS : set of markers and related texts as cell and figure number
%% OUTPUTS : No output
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% AUG 28, 2012 %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function LEGEND_GENERATOR(Marker,text,Fignum,FONTSIZE,MARKERSIZE,LWD)
% clc;clear;close all;fclose all
% Marker = {'r -*' , 'b -o' , 'g --d'};
% text = {'First Fun ' , 'Second Fun ' , 'Third Fun ' };
% FONTSIZE = 6;
% Fignum = 26;
if length(Marker)~=length(text)
error('You should have the same number of markers as texts');
end
%% FIGURE
set(0,'defaultaxesfontsize',FONTSIZE);
figure(Fignum);clf;hold on;set(gcf,'OuterPosition',[60 90 200 250],'PaperPositionMode','auto');
Leg_TEXTS = [];
for i = 1:length(Marker)
x = 0:0.1:2*pi;
y = 3*randn(1)*sin(x);
p = plot(x,y,Marker{i},'MarkerSize',MARKERSIZE,'LineWidth',LWD);
Leg_TEXTS = [ Leg_TEXTS ; {text{i}} ];
end
legend(Leg_TEXTS);
figure(Fignum);
set([gca;get(gca, 'children')], 'visible', 'off');
end
軸とそのすべての子をいつでも非表示にできます。
figure(1), clf, hold on
x = 0:0.1:2*pi;
y = sin(x);
p = plot(x,y);
legend('Sin(x)');
set([gca get(gca, 'children')], 'visible', 'off');