Hi everyone,
I have two different data sets (x,y,value) which should be displayed as bubble chart. As the values are substantially different, I want to scale the size of the bubbles for each data set individually and also use two legends. So far so good:
%some random data for the two bubble charts
nxx=5;
xx1 = rand(1,nxx);
yy1 = rand(1,nxx);
sz1 = rand(1,nxx);
xx2 = rand(1,nxx);
yy2 = rand(1,nxx);
sz2 = rand(1,nxx)*100;
figure(1)
ax11=gca;
bubblechart(ax11,xx1,yy1,sz1,[0.5 0 0.5],'MarkerFaceAlpha',0.30)
bubblesize(ax11,[5 80])
bd=bubblelegend(ax11,'Data 1','Style','telescopic'); %no worries about the legend location for now
bd.Location='northwest';
ax22 = copyobj(ax11,gcf);
bubblechart(ax22,xx2,yy2,sz2);
bubblesize(ax22,[5 25])
bd2=bubblelegend(ax22,'Data 2','Style','telescopic');
bd2.Location = 'southwest';
%%Hide the axes of the second bubblechart
ax22.Visible = 'off';
Additionally, I would like to plot these to bubblecharts on a background image. However, the legend of the first bubblechart disappears and also the bubblesize property of the second bubbleplot seems to overwrite the first one.
%some random data for the two bubble charts
nxx=5;
xx1 = rand(1,nxx);
yy1 = rand(1,nxx);
sz1 = rand(1,nxx);
xx2 = rand(1,nxx);
yy2 = rand(1,nxx);
sz2 = rand(1,nxx)*100;
figure(2)
axi=gca;
imagesc(0:1/(nxx-1):1,0:1/(nxx-1):1,rand(nxx)), hold on % some random image first
axi.Visible = 'off';
ax11=gca;
bubblechart(ax11,xx1,yy1,sz1,[0.5 0 0.5],'MarkerFaceAlpha',0.30)
bubblesize(ax11,[5 80])
bd=bubblelegend(ax11,'Data 1','Style','telescopic'); %no worries about the legend location for now
bd.Location='northwest';
ax22 = copyobj(ax11,gcf);
bubblechart(ax22,xx2,yy2,sz2);
bubblesize(ax22,[5 25])
bd2=bubblelegend(ax22,'Data 2','Style','telescopic');
bd2.Location = 'southwest';
%%Hide the axes of the second bubblechart
ax22.Visible = 'off';
hold off
I suspect that I messed up the axes objects but can't figure out how to fix it. By the way, I am not attached to the bubblechart function. I tried 'scatter' as well but there it is difficult to generate a legend based on the bubble size. Any hint is appreciated.

 채택된 답변

Voss
Voss 2022년 11월 17일
편집: Voss 2022년 11월 17일

0 개 추천

copyobj copies graphics object(s) and their descendants, so when you call copyobj after creating the image, you get a copy of the image in the new axes as well.
Does calling copyobj before creating the image give you something more like what you're after?
%some random data for the two bubble charts
nxx=5;
xx1 = rand(1,nxx);
yy1 = rand(1,nxx);
sz1 = rand(1,nxx);
xx2 = rand(1,nxx);
yy2 = rand(1,nxx);
sz2 = rand(1,nxx)*100;
figure
axi=gca; % axi and ax11 are the same axes object, by the way
ax11=gca;
ax22 = copyobj(ax11,gcf);
imagesc(0:1/(nxx-1):1,0:1/(nxx-1):1,rand(nxx)), hold on % some random image first
axi.Visible = 'off';
bubblechart(ax11,xx1,yy1,sz1,[0.5 0 0.5],'MarkerFaceAlpha',0.30)
bubblesize(ax11,[5 80])
bd=bubblelegend(ax11,'Data 1','Style','telescopic'); %no worries about the legend location for now
bd.Location='northwest';
bubblechart(ax22,xx2,yy2,sz2);
bubblesize(ax22,[5 25])
bd2=bubblelegend(ax22,'Data 2','Style','telescopic');
bd2.Location = 'southwest';
%%Hide the axes of the second bubblechart
ax22.Visible = 'off';
hold off

댓글 수: 2

Robben Hundt
Robben Hundt 2022년 11월 17일
Problem solved. Thanks Voss
Voss
Voss 2022년 11월 17일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 11월 17일

0 개 추천

Format your code as code so that we can easily copy it and run it (which I didn't).
If you want to create plots and images inside other plots and images, see attached demos. Adapt as needed.

댓글 수: 3

Robben Hundt
Robben Hundt 2022년 11월 17일
이동: Voss 2022년 11월 17일
Hi Image Analyst,
thank your for the provided scripts. I will test those. Actually I thought I have inserted code by using the "insert Matlab code" tab.
Image Analyst
Image Analyst 2022년 11월 17일
이동: Voss 2022년 11월 17일
@Robben Hundt you have to paste in the code, then highlight the code then click the code icon. I did the second snippet for you so you can see the difference and see how the second one now has a "Copy" link on it in the upper right of the shaded code black.
Do you have any pictures of what you'd like to see?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Robben Hundt
Robben Hundt 2022년 11월 17일
Will do. Next time I' prepare a properly fromatted question

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 11월 17일

댓글:

2022년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by