How to plot one data set with two y axes?

7 visualizaciones (últimos 30 días)
Thomas
Thomas el 11 de Mzo. de 2016
Comentada: Thomas el 11 de Mzo. de 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 comentario
Adam
Adam el 11 de Mzo. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Ilham Hardy
Ilham Hardy el 11 de Mzo. de 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 comentario
Thomas
Thomas el 11 de Mzo. de 2016
Yes, thank you. I've just been having a brainstorm and I think that is the best solution.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by