How to plot one data set with two y axes?

7 ビュー (過去 30 日間)
Thomas
Thomas 2016 年 3 月 11 日
コメント済み: Thomas 2016 年 3 月 11 日
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 件のコメント
Adam
Adam 2016 年 3 月 11 日
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?

サインインしてコメントする。

採用された回答

Ilham Hardy
Ilham Hardy 2016 年 3 月 11 日
%
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 件のコメント
Thomas
Thomas 2016 年 3 月 11 日
Yes, thank you. I've just been having a brainstorm and I think that is the best solution.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by