diff --git a/CHANGELOG.md b/CHANGELOG.md index 1edc628a1b..761e2d9905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - [#940](http://github.com/Nelson-numerical-software/nelson/issues/940) title bar on dark theme on Windows. - help viewer using dark theme. - adjust position `xlabel` on `figure`. +- [#975](http://github.com/Nelson-numerical-software/nelson/issues/975) Legend color (and width) is not matching that of curve in figure. ## 0.7.9 (2023-09-18) diff --git a/modules/graphics/functions/legend.m b/modules/graphics/functions/legend.m index 4b2e7f613a..d52dd3fecc 100644 --- a/modules/graphics/functions/legend.m +++ b/modules/graphics/functions/legend.m @@ -158,7 +158,8 @@ lineHandles(indexLineHandles) = line('Visible', 'off', ... 'XData', [1, 4] * nunx, ... 'YData', [ypos,ypos], ... - 'Color', children(i).Color, ... + 'Color', children(i).Color, ... + 'LineWidth', children(i).LineWidth, ... 'LineStyle', children(i).LineStyle); indexLineHandles = indexLineHandles + 1; diff --git a/modules/graphics/tests/bug_github_issue_#975.m b/modules/graphics/tests/bug_github_issue_#975.m new file mode 100644 index 0000000000..1412e18b33 --- /dev/null +++ b/modules/graphics/tests/bug_github_issue_#975.m @@ -0,0 +1,39 @@ +%============================================================================= +% Copyright (c) 2017 Allan CORNET (Nelson) +%============================================================================= +% This file is part of the Nelson. +%============================================================================= +% LICENCE_BLOCK_BEGIN +% SPDX-License-Identifier: LGPL-3.0-or-later +% LICENCE_BLOCK_END +%============================================================================= +% <-- Issue URL --> +% https://github.com/Nelson-numerical-software/nelson/issues/975 +% <-- Short Description --> +% Legend color is not matching that of curve in figure. +%============================================================================= +% <--ADV-CLI MODE--> +%============================================================================= +f = figure(); +a = [0:0.5:5]; +b = 2*a.^2 + 3*a -5; +c = 1.2*a.^2+4*a-3; +subplot(1,2,1) +plot(a,b,'-or','MarkerFaceColor','g','LineWidth',2) +xlabel('X'); ylabel('Y'); legend('Curve ','Location','NorthWest') +subplot(1,2,2) +plot(a,c,'--ok','MarkerFaceColor','c','LineWidth',2) +xlabel('X'); ylabel('Y'); legend('Curve 2','Location','NorthWest') +%============================================================================= +f = figure(); +a = [0:0.5:5]; +b = 2*a.^2 + 3*a -5; +plot(a,b,'-or','MarkerFaceColor','g','LineWidth', 3); +legend('Curve ','Location','NorthWest') +childrens = f.Children; +axe_legend = childrens(2); +line_legend = axe_legend.Children(2); +line_legend.Color = 'red'; +assert_isequal(line_legend.Color, [1 0 0]); +assert_isequal(line_legend.LineWidth, 3); +%=============================================================================