two correlations on one graph using hold on and corrplot?
조회 수: 8 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
Nachiket Katakkar
2017년 2월 23일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!