24小时热门版块排行榜    

查看: 1862  |  回复: 1

Mr_reliable

新虫 (初入文坛)

[求助] 怎么设置legend使其一半虚线一半实线? 已有1人参与

回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Jeromelei

银虫 (初入文坛)

【答案】应助回帖

★ ★ ★
感谢参与,应助指数 +1
jjdg: 金币+3, 感谢参与 2017-08-23 12:00:47
Assume you use matlab

% Generate an example input data
dt = 0.0001;
t = -0.05 : dt : 0.05;
t0 = 0 : dt : 1/150;
f75Hz_p = [zeros(1, length(t(1) : dt : t0(1) - dt)), sin(2*pi*75*t0), zeros(1, length(t0(end) + dt : dt : t(end)))];
f75Hz_n = -[zeros(1, length(t(1) : dt : t0(1) - dt)), sin(2*pi*75*t0), zeros(1, length(t0(end) + dt : dt : t(end)))];

% Plot the data without any legend
figure(1);
plot(t, f75Hz_p, 'k-');
hold on;
plot(t, f75Hz_n, 'k:');

% By default, Matlab does not provide the legend property you want
% Therefore, you could use annotation textarrow property instead
% x and y are original positions for the textarrow, dx is used for
% incremental length of the textarrow
x = 0.15; y = 0.8; dx = 0.1;

% Drawing (headless) text arrows, so that one of them can have
% a string properly which is your legend entry label. Use x,y,dx
% for positioning
annotation('textarrow', [x,x+dx], [y,y], ...
    'linestyle', '-', 'color', 'k', 'textcolor', 'k', 'headstyle', 'none')
annotation('textarrow', [x+dx+0.005, x+2*dx+0.005], [y,y], ...
    'linestyle', ':', 'color', 'k', 'textcolor', 'k', 'headstyle', 'none')
annotation('textarrow', [x + 2*dx + 0.07, x + 3*dx], [y y], ...
    'linestyle', 'none', 'textcolor', 'k', 'headstyle', 'none', 'string', '75Hz')
2楼2017-08-23 03:38:31
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 Mr_reliable 的主题更新
信息提示
请填处理意见