繁体   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