0
$\begingroup$

I make the PlotLabel for my plot by

label = {" Y1 =  4 , Y3 > 4  , Y3 < Y1 Y2 , Y3+ Y4 - |Y5| > 5 "};
color = {Blue};
legend = Row[Style[##, 30] & @@@ Transpose[{label, color}], Spacer[20]];

Plot[x^2, {x, 1, 10}, PlotLabel -> legend, Frame -> True, ImageSize -> 500, Axes -> False]

This yields a row of label up the graph. How to adjust legend in my command to get two columns of the labels instead of a row ?

i.e., I want to get up the graph:

Y1 = 4 , Y3 > 4,

Y3 < Y1 Y2, Y3+ Y4 - |Y5| > 5

Edit

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$
label = {"Y1 =  4,", "Y3 > 4", 
   "Y3 < Y1 Y2,", "Y3+ Y4 - |Y5| > 5"};
legend = Grid[
   Partition[Style[##, Blue, 30] & /@ label, 2],
   Alignment -> Left];

Plot[x^2, {x, 1, 10}, PlotLabel -> legend, Frame -> True, 
 ImageSize -> 500, Axes -> False]

enter image description here

EDIT: For multiple colors (I use Red vice Black since it is difficult for me to distinguish between Blue and Black).

colors = {Blue, Red};
n = 0;
legend = Grid[
   Partition[Style[#, colors[[Mod[n++, Length[colors]] + 1]], 30] & /@ label, 
    2],
   Alignment -> Left];

Plot[x^2, {x, 1, 10}, PlotLabel -> legend, Frame -> True, ImageSize -> 500, 
 Axes -> False]

enter image description here

EDIT 2: Or perhaps you want something like,

Column[{legend,
  Plot[x^2, {x, 1, 10}, Frame -> True, ImageSize -> 500, Axes -> False]}]

enter image description here

$\endgroup$
5
  • $\begingroup$ What if I have two colors, e.x. : label = {"Y1 = 4,", "Y3 > 4", "Y3 < Y1 Y2,", "Y3+ Y4 - |Y5| > 5", "label2"}; and colors ={Blue, Black}; $\endgroup$
    – S.S.
    Jun 10, 2016 at 0:13
  • $\begingroup$ **** Thanks **** $\endgroup$
    – S.S.
    Jun 10, 2016 at 1:39
  • $\begingroup$ Hay @Bob Hanlon, for the labels alignment up the graph, I used in legend : legend = Grid[ Partition[ Style[#, colors[[Mod[n++, Length[colors]] + 1]], 30] & /@ label, 2], Alignment -> {{-1, 1} -> Left}]; and it gave me as the attached edited figure in the question, all the labels mostly centered. How to bring all the labels to the left edge of the graph ? $\endgroup$
    – S.S.
    Jun 10, 2016 at 13:10
  • $\begingroup$ @S.S. - I don't understand what you are trying to do but look at second edit. $\endgroup$
    – Bob Hanlon
    Jun 10, 2016 at 14:02
  • $\begingroup$ It's ok @Bob Hanlon, that's just bring the label to left edge .. $\endgroup$
    – S.S.
    Jun 10, 2016 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.