Editing Legend Items for hatchfill2

25 visualizaciones (últimos 30 días)
Dani Agramonte
Dani Agramonte el 18 de Mayo de 2022
Editada: Dani Agramonte el 18 de Mayo de 2022
I want to know more about how legends and their icons work so that I can add hatching to icons for the hatchfill2 function (link).
Here's what I know about how these icons work so far
suppose we have the following code:
A = magic(4);
plot(A)
leg = legend;
We may be able to create a simple figure with a legend
Through some troubleshooting, I have found that we may obtain information about the legend icone as follows:
openvar('leg.EntryContainer.Children(j).Children(1).Transform.Children.Children')
where, in this case,
j = 1:4
since we are plotting
A = magic(4)
the resulting properties are visible:
We may verify that our understanding is correct by modifying the properties as follows:
leg.EntryContainer.Children(1).Children(1).Transform.Children.Children.LineWidth = 5;
with the following output:
If we go up a level, we can see that we can see that this is a "LineStrip" Object
If we change our initial code to
A = magic(4);
area(A)
leg = legend;
we see that we have
openvar('leg.EntryContainer.Children(1).Children(1).Transform.Children')
which itself is composed of
My question is how to edit these items. Ultimately, I think the best work around I can think of is to somehow layer on multiple LineStrip objects to create the hatching, but I can't see to figure out how to layer another obejct or if this is even the best way to do this. Any input would be appreciated.

Respuestas (1)

DGM
DGM el 18 de Mayo de 2022
There are a couple examples in the answers here:
If I recall correctly, both worked when I tested them, though I don't recall whether there were any particular caveats or benefits to either.
  1 comentario
Dani Agramonte
Dani Agramonte el 18 de Mayo de 2022
Editada: Dani Agramonte el 18 de Mayo de 2022
Looking through the code, I found that post MATLAB 9.0.0, they changed how legends worked, and the author specifically uses the legacy version of creating legends, which just creates legends as axis objects. This certainly works, but I was interested in knowing if anyone new anything about the post 9.0.0 legend objects/how their objects are made.
For reference:
% The new legend objects are pretty opaque... even diving into the
% undocumented properties, I haven't been able to find the handles of
% the legend sub-components (lines, text, etc). So I need to stick to
% the legacy version, which creates an axis object rather than legend
% object. Legacy version has bug in text properties parsing, though, so
% need to work around that too: use the new-style legend object to get
% proper text properties, then use those to alter the buggy old-style
% legend.
The solution is good though, thanks!

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by