I have generated legends using Matlab 2016b and Matlab 2013b. However, the quality of the default legend text color is not good in 2016b (see the first image). Legend texts were not even legible after printing. How I get the legend text color in 2016b as same as the default legend text color of 2013b (see the second image)? Please let me know. Thank you very much.
>>

Réponses (1)

Walter Roberson
Walter Roberson le 3 Fév 2017

0 votes

Try asking for more than one output from legend(). That will trigger it to use a different way of building the text -- and if it is still not quite right then the handles in the second output can be used to change the properties.

4 commentaires

Md Zillur Rahman
Md Zillur Rahman le 3 Fév 2017
Modifié(e) : Walter Roberson le 3 Fév 2017
Can please let me know what I have done wrong in this code?
style = @(LineStyle, MarkerStyle) plot(0,0,LineStyle,'Marker',MarkerStyle,'visible','off')
h=legend([style('-g','o'),style('-b','x'),style('-m','*'),style('--g','s'),style('--b','d'),style('--m','p')],{'Flax/PP (V_f = 0.31), E_{Charpy} = 0.00013\theta^{2}-0.024\theta+1.3','Flax/PP (V_f = 0.40), E_{Charpy} = 0.00014\theta^{2}-0.027\theta+1.6','Flax/PP (V_f = 0.50), E_{Charpy} = 0.00015\theta^{2}-0.029\theta+1.8','Flax/PP (V_f = 0.31), E_{DropWeight} = - 0.0022\theta^{2}+0.23\theta+26','Flax/PP (V_f = 0.40), E_{DropWeight} = - 0.0023\theta^{2}+0.22\theta+25','Flax/PP (V_f = 0.50), E_{DropWeight} = - 0.0017\theta^{2}+0.17\theta+20'});
hold on
ch = findobj(get(h,'children'), 'type', 'text'); %// children of legend of type text
set(ch, 'Fontsize', 30); %// set value as desired
ch = findobj(get(h,'children'), 'type', 'line'); %// children of legend of type line
set(ch, 'Markersize', 12); %// set value as desired
set(ch, 'LineWidth', 1)
set(h, 'FontName', 'Times New Roman','TextColor','black')
Walter Roberson
Walter Roberson le 3 Fév 2017
Modifié(e) : Walter Roberson le 3 Fév 2017
You need the "hold on" before you create the plots. Each of those plot() calls is clearing the axes.
Also, when you use a single output from legend() in R2014b or later, there are no children of the legend object that are type text or line. Such things exist in R2014a or earlier, but not in R2014b or later. In order to get those in R2014b or later you need multiple outputs from legend, like
[legendobj, h] = legend(Handles_of_interest, Associated_strings)
then h will include text and line objects.
Md Zillur Rahman
Md Zillur Rahman le 4 Fév 2017
I have solved the issue. I needed to make sure ''visible'' ''on'' in the following line. Thank you very much for your solution.
style = @(LineStyle, MarkerStyle) plot(0,0,LineStyle,'Marker',MarkerStyle,'visible','off')
Walter Roberson
Walter Roberson le 4 Fév 2017
visible on or off would not cause problems with the legend() call, but without the "hold on" the second call to style() is going to remove the output of the first call to style, leading to you passing deleted handles into legend()

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by