How to plot one data set with two y axes?

4 views (last 30 days)
Hi, I am trying to represent battery capacity against percentage of load covered by the capacity of the battery against the cost of the battery on one graph with two y axes. With data for battery capacity on the x axis, the left side y axis to display the percentage of load covered by the battery capacity and the second y axis on the right side to display the cost per capacity. Currently I've been using plotyy but it displays two plots and I'm only after one. I've been looking at scaling the cost axis to the percentage of load covered but I am not sure how to go about it. So far I have the following code,
%
pb = 120; % cost of battery per kWh
OfyStor = linspace(5,100,45); % percentage of the annual demand covered by the Capacity
Capacity = linspace(2,130,45); % Capacity of energy storage
cost_pb = Capacity*pb; % Total cost per battery capacity
figure(1)
[ax, hLine1, hLine2] = plotyy(Capacity, OfyStor, Capacity, cost_pb)
xlabel(ax(1), 'Capacity (kWh)');
ylabel(ax(1), '% of load stored');
ylabel(ax(2), 'Cost($)');
If anyone has any recommendation it would be greatly appreciated.
  1 Comment
Adam
Adam on 11 Mar 2016
I'm not sure I understand what you want. Since there are different functions defining percentage load and cost per capacity wouldn't you expect to have to plot two curves rather than just one curve with 2 axes?

Sign in to comment.

Accepted Answer

Ilham Hardy
Ilham Hardy on 11 Mar 2016
%
pb = 120; % cost of battery per kWh
OfyStor = linspace(5,100,45); % percentage of the annual demand covered by the Capacity
Capacity = linspace(2,130,45); % Capacity of energy storage
cost_pb = Capacity*pb; % Total cost per battery capacity
figure(1)
[ax, hLine1, hLine2] = plotyy(Capacity, OfyStor, Capacity, cost_pb)
xlabel(ax(1), 'Capacity (kWh)');
ylabel(ax(1), '% of load stored');
ylabel(ax(2), 'Cost($)');
grid on
I adjusted your code, and got two plots in one figure... Is this what you want?
  1 Comment
Thomas
Thomas on 11 Mar 2016
Yes, thank you. I've just been having a brainstorm and I think that is the best solution.

Sign in to comment.

More Answers (0)

Categories

Find more on Two y-axis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!