为什么在缩放标记时更改位置? [英] why while zooming marker changes position?

查看:82
本文介绍了为什么在缩放标记时更改位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在上面绘制图形和标记.但是,我看到了奇怪的行为-缩放时标记会更改其位置.我已经为此创建了视频(请在观看就能看到数字)

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)

我的代码:

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);

源文件: 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)

推荐答案

这是因为您设置了y轴标签

It's because you set the y-axis labels

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

现在开始缩放时,刻度本身会更改,但标签不会更改. 通过放大并同时观察y轴的范围不变,您会注意到这一点.

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.



我认为您打算使用上述yticklabel否决规则是为了提高这些ytick标签的准确性.但是您忘了使这些标签与实际值保持最新.



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.

此人: http://undocumentedmatlab.com/blog/setting- axes-tick-labels-format/花了一些时间使它成为使用回调的自动过程.

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

在文件交换上,同一个人拥有一个脚本来全部为您自动化: http ://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat

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

所以您只需要打电话

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

或您想要的任何其他格式

or any other format you want

这篇关于为什么在缩放标记时更改位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆