필터 지우기
필터 지우기

Add a scale bar to my plot

조회 수: 195 (최근 30일)
Philipe
Philipe 2014년 8월 17일
댓글: Star Strider 2020년 10월 4일
Hello, I was just wondering if there would be any way to replace the axis line for some sort of a scale bar. I am quite convinced there is no built command for this in matlab, so I was wondering how you guys would tweak the plot in order to get this. Just for the sake of illustration, this is what I have:
This is (sort of) what I wanted to obtain:
Thank you in advance for your collaboration!

채택된 답변

Star Strider
Star Strider 2014년 8월 17일
This was an interesting project!
You will probably have to experiment to get exactly the effect you want, but this will get you going:
% Create Data —
t = linspace(10,34); % ‘t’ (ms)
y = [20+5*sin(2*pi*3*t/24)+2*randn(1,100); 60+5*cos(2*pi*3*t/24)+2*randn(1,100)];
figure(1)
plot(t, y)
hold on
plot([12; 12], [-40; -20], '-k', [12; 22], [-40; -40], '-k', 'LineWidth', 2)
hold off
axis([[10 34] -60 140])
text(11.8,-30, '10 mA', 'HorizontalAlignment','right')
text(17,-45, '10 ms', 'HorizontalAlignment','center')
% set(gca, 'XTick', [10:2:34], 'XTickLabel', {[] 12:2:32 []}) % Used temporarily to get the ‘text’ positions correct
set(gca, 'Visible', 'off')
Produces:
  댓글 수: 2
Philipe
Philipe 2014년 8월 18일
Dear Star Strider,
Brilliant! By the looks of it this is exactly what I wanted. I haven't tested yet, but I will as soon as possible. Thank you for the quick reply!
Star Strider
Star Strider 2014년 8월 18일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

chen xinfeng
chen xinfeng 2016년 9월 6일
Hi, maybe you can try this Code .
The SCALEBAR is dragable & resizeable , both GUI-operate & Commandline-operate are supported.
<<www-mathworks-com-matlabcentral-answers-uploaded_files-58857-687474703a2f2f7374617469632e7a7962756c756f2e636f6d2f6368656e78696e66656e672f6a7362347676756f3262706e746d347767326136693731652f696d6167655f316172756a397573623174337074723231386562726b3031397333392e706e67.png>>
  댓글 수: 1
Jose Rego Terol
Jose Rego Terol 2020년 2월 16일
HI Chen,
Your scalebar is amazing. There is something I want to change. when I pan the plot, the bar moves with the plot. How can I keep it steady?

댓글을 달려면 로그인하십시오.


Lee Key
Lee Key 2020년 10월 2일
편집: Lee Key 2020년 10월 2일
Hi,
How to add a scale bar to a map (plot) with lat and long cordinates?
  댓글 수: 2
Sim
Sim 2020년 10월 4일
https://it.mathworks.com/help/map/graphic-scales.html
Star Strider
Star Strider 2020년 10월 4일
Sim — Thank you. I do not have the Mapping Toolbox, so could have responded here.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by