Disable FontSmoothing in Legend text objects

조회 수: 2(최근 30일)
ParkerLewis 2019년 1월 25일
편집: Brian C Coe 2019년 5월 31일
I am on Matlab R2018a. I want to disable FontSmoothing for text legend entries.
  • Setting the FontSmoothing property default vaue to 'off' for text objects doesn't seem to apply to text objects created by a legend ;
  • Using the old syntax [lgd,object_h]=legend(...) is horrible under recent releases : for some reason it leads to a drawnow inside the legend call, thus if I then want to edit the relevant properties of some of object_h (here to set their FontSmoothing to 'off'), there will be two draws, leading to a less responsive call and ugly behavior (two screen refreshes instead of just one). Although this behavior makes it unacceptable to me, I can though use these handles to then set their FontSmoothing property to 'off' and it works.
  • Not using the old syntax but only the new one lgd=legend(...) thus seems to be the only recourse. I seem to be able to find the text objects by accessing lgd.EntryContainer.NodeChildren(1).Label (1 for the first text object, 2 for the second one, etc). Problem is, property setting seems iffy at best :
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSmoothing','off') doesn't change anything.
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSize',somevalue) doesn't change anything either.
set(lgd.EntryContainer.NodeChildren(1).Label,'String','sometext') does work though.
Anyone have any idea how to proceed ?


Brian C Coe
Brian C Coe 2019년 5월 30일
편집: Brian C Coe 2019년 5월 31일
call 'legend2' instead of 'legend'... (-sigh-)
function [leg,labelhandles,outH,outM] = legend2(varargin)
% function [leg,labelhandles,outH,outM] = legend2(varargin)
% quite possibly the stupidest code i ever had to hack-up to get around a matlab stupidity.
% bcoe
if isempty(varargin)
[leg,labelhandles,outH,outM] = legend(varargin{:});
for ii=1:length(leg.ItemText)
% leg.ItemTokens(ii).graphicssmoothing='off'; %still trying to kill linesmoothing

Community Treasure Hunt

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

Start Hunting!

Translated by