MATLAB: How to create a legend with multiple colored squares filled squareslegend Hey, how can I create a legend for the background of the following plot? I would like to have a textbox with 3 colored squares (like the background) and the related category. Thanks for your help!! Best Answer % Create an axehAxe = axes(...);% Get your patches handleshGreen = patch(hAxe, ...);hYellow = patch(hAxe, ...);hRed = patch(hAxe, ...); % Add legendlegend(hAxe, [hGreen hYellow hRed], {'Green', 'Yellow', 'Red'}) Related SolutionsMATLAB: Legend error. How to fix Move this line to end, after copying the line objects.legend('\alpha=0','\alpha=1/9','\alpha=1/10','location', 'northeast')Also, it looks like each line is represented twice since your legend contains two lines for each color. Examine the outputs of h1 h2 h3 to see if there is more than 1 handle in each. If so, and if the lines are identical, use, legend([h1(1),h2(1),h3(1)], '\alpha=0','\alpha=1/9','\alpha=1/10','location', 'northeast') MATLAB: Fontsize and properties of Xticklabels using figure handles "How do I cange the Xticklabels of a plot using figure handles?"Get the axis handle from the figure handle. ax = gca(figureHandle); Get the XAxis handle from the axis handle and set the FontSize of the x-axis only.ax.XAxis.FontSize = 16;or set the fontsize of the entire axis (x & y)ax.FontSize = 14; Set the XTick and XTick labelsax.XTick = 1:4; ax.XTickLabel = {'A' 'B' 'C' 'D'}; Related QuestionLegend error. What did I do wrong herePlotyy y axes overlapLegend for yyaxis at two different locations
Best Answer