two correlations on one graph using hold on and corrplot?

8 visualizaciones (últimos 30 días)
Jessica Benady-Chorney
Jessica Benady-Chorney el 16 de Feb. de 2017
Respondida: Nachiket Katakkar el 23 de Feb. de 2017
Hello,
I am trying to create a graph showing two linear correlations. Based on what I have found so far, I think my code should look like this:
corrplot(y(:,[1 2]),'varnames'{'var1 var2'}) %generate graph of 1st correlation
hold on
corrplot(y(:,[1 2]),'varnames'{'var1 var2'}) %generate graph of 2nd correlation and overlap it onto the %first graph
but when I run this I get two separate graphs.
What am I doing wrong?
Thank you very much!

Respuestas (1)

Nachiket Katakkar
Nachiket Katakkar el 23 de Feb. de 2017
The "hold on" command applies to an axes object and not to the figure. The "corrplot" function creates a new figure, with several axes objects, each time it is called and therefore the "hold on" command does not apply here.
I am not entirely sure about why you wish to overlay the two outputs, but one workaround would be to access the each of the axes objects and copy the axes children as shown here:
%%Create the two corrplots and obtain figure handles
% This section will create 2 different figures, one for each corrplot
load Data_Canada  
% First call to corrplot
[R,PValue] = corrplot(DataTable,'tail','right');
f1 = gcf;
% Second call to corrplot
corrplot(DataTable(:,1:2),'type','Kendall','testR','on');
f2 = gcf;
%%Copy plots from one axes to another
% Obtain axes handles
ax1 = f1.Children(1);
ax2 = f2.Children(1);
% Copy first axes' children(plot objects) to second axes
copyobj(ax1.Children,ax2)
You might want to run each section individually to notice the difference. Plots from one of the first figure's axes have been copied over to the second figure's top-right axes.

Categorías

Más información sobre Specifying Target for Graphics Output 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