9

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.

2 Answers2

18

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

kale
  • 10,922
  • 1
  • 32
  • 69
5

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

Mike Honeychurch
  • 37,541
  • 3
  • 85
  • 158