Scatter and legend functions are not working well with each other, when working with Export Setup.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sagar D Patel
el 27 de Mayo de 2021
Comentada: Sagar D Patel
el 10 de Jun. de 2021
With the code given below to create a scatter plot and edit the legend marker size:
b=figure;
scatter(LE,pred_D,300,'b','o');
hold on;
scatter(LE,measured_D,300,'r','d');
[~, hobj, ~, ~] = legend({'Predicted','Measured'},'Fontsize',12,'FontName', 'Arial','Location','Best');
M = findobj(hobj,'type','patch');
set(M,'MarkerSize',sqrt(600));
xlabel('$E^*/\sqrt{v^*}$','Interpreter','latex');
ylabel('Melt pool depth (μm)');
set(gca, 'FontName', 'Arial', 'FontSize', 12);
I am able to obtain the following output:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632465/image.png)
I intentionally have these larger marker sizes as Matlab seems to reduce them drastically when I use settings inside of File>Export Setup such as the ones given below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632470/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632475/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632480/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632485/image.png)
These "Export Setup" settings make the scatter points ready for publication, but the legend seems to misbehave (changes size and marker thickness) as shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632490/image.png)
The same Export Setup settings work well with the gscatter code:
g=figure;
hold on;
pPlot=gscatter(v_star,E_star,melting_mode,'kbrm','so^d',20,'on','Dimensionless Velocity','Dimensionless Heat');
l= findobj(gcf,'tag','legend'); set(l,'location','northwest');
[hleg,att] = legend('show');
set(gca,'xscale','log')
set(gca,'yscale','log')
xlim([1 10])
ylim([10 200])
with before/after "Export Setup" images shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632495/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/632500/image.png)
0 comentarios
Respuesta aceptada
Shraddha Jain
el 9 de Jun. de 2021
Editada: Shraddha Jain
el 9 de Jun. de 2021
Hi Sagar,
You are not able to modify the properties of legend while displaying scatter plot because of the way the legend object has been created in the code below,
[~, hobj, ~, ~] = legend({'Predicted','Measured'},'Fontsize',12,'FontName','Arial','Location','Best');
If you replace the above code with,
legend({'Predicted','Measured'},'Fontsize',12,'FontName','Arial','Location','Best');
the changes made in the Export Setup > Fonts of the MATLAB Figure will be reflected in the legend as well.
Hope this helps!
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend 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!