In "scatter"-related legends, how to make larger symbols ?

2 views (last 30 days)
I tried to adapt the Adam Danz's solution for customising the legend properties related to a "plot", to, instead, the legend properties related to a "scatter". As we can see in the following example, in the legend, the round symbol indicating "foo" and related to the "plot" is large and its size can be customised through the command:
hCopy(1).MarkerSize = 50;
However, If I try to make the round symbol indicating "boo" and related to the "scatter" plot, a bit larger, through the command
hCopy(2).SizeData = 100;
the size of the symbol indicating "boo" does not change at all.
How can I make the symbol size in the legend and related to the "scatter" a bit larger ?
% Create the plot
ax = axes();
hold on
h(1) = plot(linspace(1,5,25), rand(1,25), 'ro', 'DisplayName', 'foo');
h(2) = scatter(1:5, rand(1,5), 300,'b','DisplayName', 'bar');
% copy the objects
hCopy = copyobj(h, ax);
% replace coordinates with NaN
% Either all XData or all YData or both should be NaN.
set(hCopy(1),'XData', NaN', 'YData', NaN)
set(hCopy(2),'XData', NaN', 'YData', NaN)
% Alter the graphics properties
hCopy(1).MarkerSize = 50;
hCopy(2).SizeData = 100;
% Create legend using copied objects

Answers (1)

dpb on 30 Aug 2022
My experimenting with legend and scatter wasn't very fruitful; the legend was created with a given size (height, primarily the issue) and while could use undocumented properties to resize the box itself, the internals that control the size of the object drawn remained inscrutable (at least within the time I had/was wiling to spend spelunking).
If you can make it work with plot as desired, then forget about using scatter; add the hidden object as another line handle with the marker of choice and size, and then juse that handle to legend to get its properties onto the legend.
As an aside I've railed since the introduction of HG2 and the new, "improved" legend about TMW having made the object so opague that one can no longer make customizations easily as could with the old axes and its properties. It's a real time waster towards productive work to have to mess around with stuff like this that should be trivial.
dpb on 31 Aug 2022
"What a tangled web...", indeed. This has always been, but where the internal review is/was to provide consistency in inputs between similar functions...
Similar thing with the new(ish) readXXX functions -- they've changed the names of some of the historical named parameters for no good reason at all -- then added code to recognize the historical precedent name as well--what's the point in adding nothing functional but bloating code base?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!