How to plot one data set with two y axes?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Thomas
am 11 Mär. 2016
Kommentiert: Thomas
am 11 Mär. 2016
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 Kommentar
Adam
am 11 Mär. 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?
Akzeptierte Antwort
Ilham Hardy
am 11 Mär. 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?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Two y-axis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!