Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

matlab - why while zooming marker changes position?

I plot graph and markers on it. However I see strange behavior - marker changes it's position while zooming. I've created video about that (please switch to fullhd while watching to be able to see numbers)

my code:

clear

fDevide = fopen('devideHistory.log');
data = textscan(fDevide, '%f:%f:%f:%f %f,%f %f,%f');
fclose(fDevide);

% hh:min:sec:millisec
secvec = [60*60 60 1 1e-3];
x = [data{1:4}] * secvec';

flvec = [1 1e-16];
y = [data{5:6}] * flvec';

xindays = x / (24*60*60);

plot(xindays, y);
set(gca, 'YTickLabel', get(gca,'YTick'))
datetick('x', 'HH:MM:SS');

hold on

fDeals = fopen('deals.log');
data = textscan(fDeals, '%f:%f:%f:%f %f,%f %f,%f %f,%f %f');
fclose(fDeals);

% hh:min:sec:millisec
secvec = [60*60 60 1 1e-3];
x = [data{1:4}] * secvec';

flvec = [1 1e-16];
y = [data{5:6}] * flvec';

xindays = x / (24*60*60);

plot(xindays, y, 'go','MarkerSize',6,'LineWidth',3);

source files: devideHistory.log deals.log

The question is why marker changes it's position. I expect it to be always at the same position (from file deals.log)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's because you set the y-axis labels

set(gca, 'YTickLabel', get(gca,'YTick'))

when you now start zooming, the ticks themselves change, but the labels don't. You notice this by zooming in and at the same time observing that the range of the y-axis does not change.



I think what you intended to do with the above yticklabel overruling is increase the accuracy of those ytick labels. But you forget to keep those labels up to date with the actual values.

This guy: http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/ has spent some time of making this an automatic process using callbacks.

On the file exchange the same person has a script to all automate it for you: http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat

so you only have to call

ticklabelformat(gca,'y','%.6g')

or any other format you want


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...