Home > Back-end >  How to set the axis of symmetry for a line graph and scale the image adaptively around the axis of s
How to set the axis of symmetry for a line graph and scale the image adaptively around the axis of s

Time:08-13

I have some data about how Apples exchange to Oranges in 5 periods in a market.

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. For example, In the first period, 1 Apples exchange to 20 Oranges; and in the forth period, 20 Apples exchange to 1 Orange. Next, I want to plot the Apple2OrangeExchangeRate in a line graph. 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. If I set Apple2OrangeExchangeRate=1 as the axis of symmetry, they are be of equal status. It's not symmetric about 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. So, for example, how can I make "20:1" and "1:20" look equal in a line graph?


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-')

enter image description here Maybe I can 'scale' the largest data(In this case is '3') into '2'(but still keep the orginal data in Y axe)? So '0' and '3' are symmetric about '1'.

CodePudding user response:

A log scale plot will illustrate the "symmetry" of 20:1 vs 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 figure showing the log plot of Apples/Oranges as described

  • Related