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

I have some data about how Apples exchange to Oranges in 5 periods in a market.我有一些关于苹果如何在市场上 5 个时期内兑换成橙子的数据。

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

The variable Apple2OrangeExchangeRate describes in each period how Apples exchange to Oranges.变量 Apple2OrangeExchangeRate 描述了每个时期苹果如何与橘子交换。 For example, In the first period, 1 Apples exchange to 20 Oranges;例如,第一期,1个苹果换20个橙子; and in the forth period, 20 Apples exchange to 1 Orange.第四期,20个苹果换1个橙子。 Next, I want to plot the Apple2OrangeExchangeRate in a line graph.接下来,我想将 plot Apple2OrangeExchangeRate 放在折线图中。 In fact, the outcome in the first period and the forth period is symmetrical, because one is 1Apple:20Oranges, and the other is 20Apples:1Orange.事实上,第一期和第四期的结果是对称的,因为一个是 1Apple:20Oranges,另一个是 20Apples:1Orange。 If I set Apple2OrangeExchangeRate=1 as the axis of symmetry, they are be of equal status.如果我将 Apple2OrangeExchangeRate=1 设置为对称轴,则它们的状态相同。 它不是关于 Apple2OrangeExchangeRate=1 对称的

But in my line graph the first period(rate=20) is too prominent, and the forth period(rate=1/20) is too inconspicuous.但在我的折线图中,第一个周期(rate=20)太突出,第四个周期(rate=1/20)太不显眼。 So, for example, how can I make "20:1" and "1:20" look equal in a line graph?那么,例如,如何使“20:1”和“1:20”在折线图中看起来相等?

A log scale plot will illustrate the "symmetry" of 20:1 vs 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';

Result:结果:

MATLAB 图显示了 Apples/Oranges 的对数图,如所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM