4
$\begingroup$

I want to create a timeline using TimelinePlot. Above every element I want to write some text/label. Right now I am using Labeled for that. Which results in the following plot:

example timeline plot

data1 = {0, 2.68*60, 3.32*60, 07.18*60};
data2 = {3.48*60, 3.48*60, 4.23*60};
test = TimelinePlot[{
   {Labeled[data1[[1]], "text1", Above],
    Labeled[data1[[2]], "text2", Above],
    Labeled[data1[[3]], "text3", Above],
    Labeled[data1[[4]], "text4", Above]},
   {Labeled[data2[[2]], "text5", Above],
    Labeled[data2[[3]], "text6", Above]}
   }
  , PlotLegends -> Placed[{"1", "2"}, Below]
  , Filling -> Axis
  , LabelStyle -> {FontColor -> Black, FontSize -> 16, 
    FontFamily -> "Arial"}
  , PlotTheme -> "Monochrome"
  ]

The Plot looks exactly as I want, except for the font size of the labels. How can I change the font size of text1 to text6? LabelStyle -> Directive[FontSize -> 16] does not work inside TimelinePlot. Neither does Callout instead of Labeled.

Removing Above from Labeled makes the labels change to the correct font size, but the whole plot does not look as intended anymore:

example timeline2 plot

$\endgroup$
1
  • 2
    $\begingroup$ Since you are going to the double of constructing each Labeled expression, add Style to your text label, eg Labeled[data[[1]], Style["text1", 16], Above]. You will probably want to generate the entries programmatically; maybe look at MapThread. $\endgroup$
    – MarcoB
    Mar 11 at 14:19
3
$\begingroup$

You can use BaseStyle -> {FontSize -> 16, FontFamily -> "Arial"}:

TimelinePlot[{{Labeled[data1[[1]], "text1", Above], 
   Labeled[data1[[2]], "text2", Above], 
   Labeled[data1[[3]], "text3", Above], 
   Labeled[data1[[4]], "text4", Above]}, 
  {Labeled[data2[[2]], "text5",  Above], 
   Labeled[data2[[3]], "text6", Above]}}, 
 PlotLegends -> Placed[{"1", "2"}, Below],
 Filling -> Axis, 
 BaseStyle -> {FontSize -> 16, FontFamily -> "Arial"}, 
 PlotTheme -> "Monochrome"]

enter image description here

$\endgroup$
1
$\begingroup$

Another way is set PlotLayout -> "Stacked" etc.

data1 = {0, 2.68*60, 3.32*60, 07.18*60};
data2 = {3.48*60, 3.48*60, 4.23*60};
test = TimelinePlot[{{Labeled[data1[[1]], "text1"], 
    Labeled[data1[[2]], "text2"], Labeled[data1[[3]], "text3"], 
    Labeled[data1[[4]], "text4"]}, {Labeled[data2[[2]], "text5"], 
    Labeled[data2[[3]], "text6"]}}, 
  PlotLegends -> Placed[{"1", "2"}, Below], Filling -> Axis, 
  LabelStyle -> {FontColor -> Black, FontSize -> 16, 
    FontFamily -> "Arial"}, PlotTheme -> "Monochrome", 
  PlotLayout -> "Stacked"]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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