Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Searching got me peripherally related threads, but not exactly what I was looking for.

I'm making some graphs which I want to use on exams. Sometimes, labels (specifically in AxesLabel and PlotLabel) that are longish can be a hassle. Is there a way to introduce a line break in these labels to make them fit better in the space that I have? Thanks in advance.

share|improve this question
    
I get the feeling this question is probably a duplicate –  Mike Honeychurch Jul 25 at 3:47

2 Answers 2

up vote 9 down vote accepted

Try this:

Plot[Sin[2 x], {x, -Pi, Pi}, 
  AxesLabel -> {"This is\n an axes label", None}]

enter image description here

And here's the same using FrameLabel instead of AxesLabel.

Plot[Cos[2 x], {x, -Pi, Pi}, Frame -> True, 
 FrameLabel -> {{"This is\n a y frame label",None}, 
 {"This is\n an x frame label", None}}]

enter image description here

This is covered in the documentation under Newlines and Tabs in Strings.

And if you want more control, you can even use Columns and Grids:

Plot[Cos[2 x], {x, -Pi, Pi}, Frame -> True, 
 FrameLabel -> {{Column[{"Column1", "Column2"}], None},
 {Grid@{{1, 2}, {3, 4}}, None}}]

enter image description here

share|improve this answer
    
I tried \n but it just shows up in the label that way, no line break. Am I missing something? –  Zippy The Pinhead Jul 25 at 19:06
    
I notice that imposing formatting on the text seems to be the cause. But thanks! –  Zippy The Pinhead Jul 25 at 19:12

An alternative to manually setting line breaks is to set a label size and then let the label break as needed:

Plot[Cos[2 x], {x, -Pi, Pi}, Frame -> True, 
 FrameLabel -> {{Pane["This is a y frame label", {50, All}], 
    None}, {Pane["This is an x frame label", {50, All}], None}}] 

enter image description here

share|improve this answer
    
Why 50 and not 45 (which gives the same result) ? Why 45 and not 20 ? –  eldo Jul 25 at 0:51
1  
@eldo why not 55, why not 150, why not 126, why not 87. the whole point is to choose whatever label size you want. If you like 20 then choose 20. –  Mike Honeychurch Jul 25 at 1:11
    
BTW I think this Q&A is probably a duplicate –  Mike Honeychurch Jul 25 at 3:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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