What and how to understand the math behind YYaxis syntax in MATLAB

1 次查看(过去 30 天)
Dear all, I am interested to know how does MATLAB under the syntax YYaxis was able to fitted two signals with different scales. For instant, in the documentation under the example Highway Data, MATLAB fitted perfectly the Licensed Drivers and Vehicle Miles Traveled.
Is it just a proportional fit such that using very simple convex optimization problem, where X = bY? I had tried to run the code line by line as it travel across different functions, however, unless I overlook, there was no specific line that show the fitting process between the signal/variables.
Do you mind to share what approach or technique that MATLAB used to get the common scale? I believe, by understand the principle behind it, we can further tune the code that suit our requirement.
Thanks in advance!.
The code for the said example as below
load('accidents.mat','hwydata')
ind = 1:51;
drivers = hwydata(:,5);
yyaxis left
scatter(ind,drivers)
title('Highway Data')
xlabel('States')
ylabel('Licensed Drivers (thousands)')
pop = hwydata(:,7);
yyaxis right
scatter(ind,pop)
ylabel('Vehicle Miles Traveled (millions)')

回答(1 个)

Walter Roberson
Walter Roberson 2017-10-6
No fitting is done.
When you do not give a YLim (ylimit) then it is chosen automatically by searching for "nice" multiples involving the range. Roughly speaking, log10() of the max() minus the min() is taken, and that determines the power of 10 for the marks, with algorithm preferring ticks at multiples of 2, 5, or 10 within that range .
In the case of that example, the data just happens to line up neatly, suggesting that there might be a mathematical relationship between the two quantities.
  1 个评论
balandong
balandong 2017-10-6
Hi Walter,
Thanks for the insight!
As you can see in the following figure (tqken from Figure link), there are totally two different scale for the left and right Y-axis. My best guest, some scaling factor must take place to squeeze or enlarge the blue and orange lines, respectively.
May I know what exactly do you mean by MATLAB " chosen automatically by searching for "nice" multiples involving the range" . What process has been automated?
Really appreciate for your wisdom.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by