簡體   English   中英

如何設置折線圖的對稱軸並圍繞 Matlab 中的對稱軸自適應縮放圖像?

[英]How to set the axis of symmetry for a line graph and scale the image adaptively around the axis of symmetry in Matlab?

我有一些關於蘋果如何在市場上 5 個時期內兌換成橙子的數據。

Period = 1:5;
Apple = [1 2 6 20 3];
Orange = [20 4 15 1 18];
Apple2OrangeExchangeRate = Apple.\Orange
plot(Period,Apple2OrangeExchangeRate,'o-')

變量 Apple2OrangeExchangeRate 描述了每個時期蘋果如何與橘子交換。 例如,第一期,1個蘋果換20個橙子; 第四期,20個蘋果換1個橙子。 接下來,我想將 plot Apple2OrangeExchangeRate 放在折線圖中。 事實上,第一期和第四期的結果是對稱的,因為一個是 1Apple:20Oranges,另一個是 20Apples:1Orange。 如果我將 Apple2OrangeExchangeRate=1 設置為對稱軸,則它們的狀態相同。 它不是關於 Apple2OrangeExchangeRate=1 對稱的

但在我的折線圖中,第一個周期(rate=20)太突出,第四個周期(rate=1/20)太不顯眼。 那么,例如,如何使“20:1”和“1:20”在折線圖中看起來相等?

對數比例 plot 將說明 20:1 與 1:20 的“對稱性”:

Period = 1:5;
Apple = [1 2 6 20 3];
Orange = [20 4 15 1 18];
Apple2OrangeExchangeRate = Apple.\Orange;
% Plot the log of the exchange rate
ax = axes();
plot(ax, Period,log10(Apple2OrangeExchangeRate),'o-')
% Set the x-axis to go through the origin to emphasize the symmetry
ax.XAxisLocation = 'origin';
ax.YLabel.String = 'log(Apple/Orange)';

% If you want, you can also display the actual exchange rate 
%    values on a second y-axis:
% Get the original y limits
ylimits = ax.YLim;
% Add a second y-axis
yyaxis(ax, 'right');
% Set it to a log scale so it looks nice
ax.YScale = 'log';
% Set the new y-limits to match the old ones on a log scale
ax.YLim = 10.^ylimits;
% Set the 2nd y-axis label
ax.YLabel.String = 'Apple/Orange';

結果:

MATLAB 圖顯示了 Apples/Oranges 的對數圖,如所述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM