Plotting more than one graph

I am attempting to produce 2 graphs (see below) however after running the code only one graph (Stock Price) is being displayed. How can I get them both to show?
% LogPriceReturn Graph
x = Timestep; % sets x axis equal to the 'Timestep'
y = LogPriceReturn; % sets y axis equal to the 'LogPriceReturn'
plot(x,y, 'Marker','o', 'MarkerFaceColor','black'); hold on % plots graph of x and y, using 'hold on' command to retain each loop result
title('Log Price Return'); % sets the title of graph
xlabel('Timestep'); % sets x-axis label of graph
ylabel('Log Price Return Graph'); % sets y-axis label of graph
axis([1 n -1.5 1.5]); % formats axis limits
%StockPrice Graph
x = Timestep;
y = StockPrice;
plot(x,y, 'Marker','o', 'MarkerFaceColor', 'black'); hold on
title('Stock Price');
xlabel('Timestep');
ylabel('Stock Price');
axis([1 n -1.5 1]);

 Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de En. de 2017

0 votos

Before you start the second plot use
hold on

4 comentarios

MK96
MK96 el 28 de En. de 2017
I've tried this but still only shows one graph
Walter Roberson
Walter Roberson el 28 de En. de 2017
Notice that you have used the same marker and same color for both. It might not be obvious that there are two results in the same graph.
Your second axis call is going to override the first because you are plotting in the same axes. That is going to narrow the view, potentially cutting off some data that was plotted the first time.
If your stock prices are not in the range of 0 to 1 dollars then they are not going to fit on the axes you gave. But log of the return would not fit unless the log was between -1 and 1 which would correspond to 0.1 to 10 if we assume log10. Stocks in the range of 0 to 1 dollars seldom have a 10 to 1 return unless they are penny stocks with ultra low volume where single trades can change the average price on paper.
I have to wonder whether your axis scales are correct.
David Ramirez
David Ramirez el 1 de Jul. de 2020
I think he means he wants to seperate graphs and only one populates. I am having the same problem
Walter Roberson
Walter Roberson el 1 de Jul. de 2020
I suggest that for debugging purposes that you use four subplots, the first as normal, the second one showing the first plot, the third one showing the second plot, and the fourth showing the interpolated difference between the two (or just subtract the two if they have the same time scale.) This will give you information to determine whether the plots are in fact similar enough that they are overlaying each other, and will also give you information about whether one of the plots is being badly cut off due to the xlim / ylim

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 28 de En. de 2017

Comentada:

el 1 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by