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!