How to make 4D scatter bubble plot marker size legend?

1 回表示 (過去 30 日間)
Andrew Robison
Andrew Robison 2017 年 9 月 29 日
回答済み: Walter Roberson 2017 年 10 月 5 日
I am looking to display results from a multi-objective optimization with four objective functions. The 'scatter' function works nicely to display the data, but I cannot figure out how to make a proper legend for the circle sizes. Here's an example script for what I am trying to do:
%4D Bubble Plot Script
%Takes 4 Objective function values and makes a bubble plot to visualize the
%data
clear
clc
close all
%Pareto Values
x1=10*rand(100,1);
x2=10*rand(100,1);
x3=10*rand(100,1);
x4=10*rand(100,1);
%Sort According to decreasing diameter
[x4,I]=sort(x4);
x4=wrev(x4);
x1=wrev(x1(I));
x2=wrev(x2(I));
x3=wrev(x3(I));
%Generate Figure
figure()
scatter (x1,x2,100*x4,x3,'filled','MarkerEdgeColor',[0 0 0],'LineWidth',0.5)
colormap jet
c=colorbar('Limits',[0 10],'Ticks',0:10,'FontName','Times New Roman','FontSize',14);
c.Label.String = 'x_{3} [units]';
c.Label.FontSize=14;
axis([0 10 0 10])
xlabel('x_{1} [units]')
ylabel('x_{2} [units]')
xticks(0:10)
yticks(0:10)
set(gca,'FontName','Times New Roman','FontSize',14,'LineWidth',1.5);
set(gcf,'color','w');
I would like to make a legend like the one I made in inkscape as an example in this figure. For the fourth variable x_4, I added a scaling factor in the 'scatter' function to make the circles appear slightly larger, so I would also like to be able to account for that in the legend if possible.
Also, when the figure is exported as an emf the '[units]' gets put into the subscript for both vertical axes, but the legend labels appear correctly in the MATLAB figure though. Any ideas how to correct that?

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 10 月 5 日
legend() will only create one entry for each plot handle, but scatter() only creates one plot handle per call.
Work around:
Lh(1) = scatter(nan, nan, min(x4)*100, 'k');
Lh(2) = scatter(nan, nan, max(x4)*100, 'k');
legend(Lh, {'min {x4}', 'max {x4}'} )

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by