如何在MatLab中设置折线图的对称轴,并围绕对称轴自适应地缩放图像?

laximzn5  于 2022-11-15  发布在  Matlab
关注(0)|答案(1)|浏览(223)

我有一些关于苹果在一个市场上如何在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个橙子。接下来,我想在折线图中绘制Apple2OrangeExchangeRate。事实上,第一期和第四期的结果是对称的,因为一个是1苹果:20橙色,另一个是20苹果:1橙色。如果我将Apple2OrangeExchangeRate=1设置为对称轴,则它们具有相同的状态。

但在我的折线图中,第一个周期(Rate=20)太突出,而第四个周期(Rate=1/20)太不明显。那么,例如,我如何使“20:1”和“1:20”在折线图中看起来相等?

Period = 1:5;
Apple=[3 0 2 0 1];
Orange = [1 1 0 0 3];
Apple2OrangeExchangeRate=[1/3 0 0 0 3];
plot(Period,Apple2OrangeExchangeRate,'o-')


也许我可以将最大的数据(在本例中为‘3’)‘缩放’到‘2’(但仍保留原始数据在Y轴上)?所以‘0’和‘3’关于‘1’是对称的。

xu3bshqb

xu3bshqb1#

对数比例图将说明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';

结果:

相关问题