legendflex-pkg icon indicating copy to clipboard operation
legendflex-pkg copied to clipboard

The legend is not aligned on the y-axis, when ncol is not equal to 0

Open mengyingzhou opened this issue 4 years ago • 1 comments

hi Thanks for your wonderful work. I find a slight mistake when I apply the legendflex in bar function. When ncol is set to 3, the legend is not aligned on the y-axis. The second legend is slightly lower than the first legend. This is my code:

figure(1);clf;
h = bar(rand(10,3));
hatchfill2(h(1),'single','HatchAngle',0,'HatchDensity',30,'HatchColor','w','HatchLineWidth',1.5);
hatchfill2(h(2),'single','HatchAngle',135,'HatchDensity',30,'HatchColor','w','HatchLineWidth',1.5);
hatchfill2(h(3),'single','HatchAngle',45,'HatchDensity',30,'HatchColor','w','HatchLineWidth',1.5);
[~,legend_h,~,~] = legendflex(h,{'e1','e2','e3'},'anchor', [2 6],'buffer', [ 0  10], 'FontSize', 20, 'ncol', 3, 'box', 'on');

Then, I checked the YData of the legend and found that they are not consistent with each other in the forth and fifth elements:

>> legend_h(length(h)+1).Children(1).YData

ans =

    9.2889
   34.3889
   34.3889
    9.2889
    9.2889

>> legend_h(length(h)+2).Children(1).YData

ans =

    7.3694
   32.4694
   32.4694
    7.3694
    7.3694

thx!

mengying

mengyingzhou avatar Apr 20 '20 02:04 mengyingzhou

Thank you for noting this. It appears to be related to the font size modification; I'll have to determine whether the mistake is in my code or in the underlying call to legend.

kakearney avatar Aug 27 '20 01:08 kakearney