Text in a patch
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have a problem which seems simple but I cannot find an easy way to solve it.
I create a lot of patches (hexagons) in a plot, and I have to display an information inside each patch. The problem is that number of patches can vary a lot, and I have to be able to read the information well. The other thing that I want is to have the text size increased when I resize the window (as the patches do), so I want to use normalized units.
Right now it is like that :
x=xcoordinates;
y=ycoordinates;
c=values;
for i=1:length(x)
p=patch(x(i),y(i),c(i));
tx=text(x(i), y(i), num2str(c(i)),'HorizontalAlignment','center','VerticalAlignment','middle','FontUnits', 'Normalized', 'FontSize', 0.1);
hold on
end
I would like to use the normalized size "size" that has each patch "p" to create a text "tx" and adapt the font size "fsize" to this "size".
Do you know a straightforward way to do this?
Thanks!
0 Kommentare
Antworten (2)
Walter Roberson
am 14 Mai 2018
I used to set userdata for text objects reflecting relative font size. Then when I got a figure resize callback, I would figure out the base size and findobj() to get the text objects with the special marks and use the information there to modify the computed base font size.
I used this approach instead of a plain set(findobj('type', 'text'), 'fontsize', X) in order to allow for headers (larger than normal) and explanatory text (smaller)
Though really what I did was use this marking process along with a user font size preference, changing all the objects when the user modified their preferences. I also implemented dynamic uisizing and text wrapping so that as the user made the text larger the boxes did not overflow. The logical also auto positioned controls according to a system of layout rules.
... Basically my boss used a different sized monitor with different sized pixels and configuring against their monitor would have had the interface look crappy for everyone else, so I did autolayout to make everyone happy.
Autolayout is harder to make look good than you might think!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!