Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to place AxesLabels:

  1. For x axis at center of the Histogram and LineListPLots.
  2. For y axis rotated 90 degree anti clockwise.

I don't see any options for it?

Histogram[Table[zcb[i],{i,mcRunHJM}],AxesLabel->{Price,Relative Frequency}]

ListLinePlot[Table[zcb[i],{i,mcRunHJM}],PlotRange->{{0,mcRunHJM},{0.9,1.1}}, PlotLabel->Style["Convergence",FontSize->12],AxesLabel->{Simulation Step,Price}]  

enter image description here

share|improve this question
Take a look at FrameLabel. – VLC Jan 16 '13 at 15:57
Duplicate of this? – m_goldberg Jan 16 '13 at 17:04
up vote 18 down vote accepted

For the histogram:

  RandomReal[NormalDistribution[0, 1], 200]], {Rotate[
   "Relative Frequency", 90 Degree], "Price"}, {Left, Bottom}]

enter image description here


Further to Sebastian's comment to add stats:-

data = RandomReal[NormalDistribution[0, 1], 200];
  Epilog -> Inset[Framed[Grid[{
       {"Mean =", Mean[data]},
       {"Max =", Max[data]},
       {"Min =", Min[data]}},
      Alignment -> {{Left}}], Background -> White],
    {Right, Top}, {Right, Top}],
  BaseStyle -> {FontFamily -> "Courier"}], {Rotate[
   "Relative Frequency", 90 Degree], "Price"},
 {Left, Bottom}]

enter image description here

To show two data sets, two methods:-

dataA = RandomReal[NormalDistribution[0, 1], 200];
dataB = RandomReal[NormalDistribution[0, 1], 100];

Labeled[Histogram[{dataA, dataB},
  ChartStyle -> {ColorData[3, 4], ColorData[3, 6]},
  ChartLegends -> {
    Style[StringJoin["Set A mean = ",
      ToString[Round[Mean[dataA], 10.^-6]]],
     FontFamily -> "Courier"],
    Style[StringJoin["Set B mean = ",
      ToString[Round[Mean[dataB], 10.^-6]]],
     FontFamily -> "Courier"]}],
 {Rotate["Relative Frequency", 90 Degree],
  "Price                         "}, {Left, Bottom}]

enter image description here

For more control of appearance the second method uses ShowLegend:-

(* Specify common bin division size *)
histA = Histogram[dataA, {0.5}];
histB = Histogram[dataB, {0.5}];
(* Find common plot range and axes origin *)
minmaxA = First[PlotRange /. Options[histA, PlotRange]];
minmaxB = First[PlotRange /. Options[histB, PlotRange]];
tAB = Transpose[{minmaxA, minmaxB}];
minmaxAB = {Min[First[tAB]], Max[Last[tAB]]};
aoA = First[AxesOrigin /. Options[histA, AxesOrigin]];
aoB = First[AxesOrigin /. Options[histB, AxesOrigin]];
aoAB = Min[aoA, aoB];

   Histogram[dataA, {0.5},
    ChartBaseStyle -> {ColorData[3, 4], Opacity[0.5]}],
   Histogram[dataB, {0.5},
    ChartBaseStyle -> {ColorData[3, 6], Opacity[0.5]}],
   PlotRange -> {minmaxAB, {All, All}},
   AxesOrigin -> {aoAB, 0}],

  {{{Graphics[{ColorData[3, 4], Opacity[0.5], Rectangle[]}], 
     Style[StringJoin["Set A mean = ",
       ToString[Round[Mean[dataA], 10.^-6]]],
      FontFamily -> "Courier"]}, {Graphics[{ColorData[3, 6], 
       Opacity[0.5], Rectangle[]}], Style[StringJoin["Set B mean = ",
       ToString[Round[Mean[dataB], 10.^-6]]],
      FontFamily -> "Courier"]}},
   LegendPosition -> {0.2, 0.6},
   LegendSize -> {1.1, 0.25},
   LegendTextSpace -> 8,
   LegendShadow -> None}],
 {Rotate["Relative Frequency", 90 Degree], "Price      "},
 {Left, Bottom}]

enter image description here

And a matching ListLinePlot:-

linedataA = RandomReal[NormalDistribution[0, 1], 20];
linedataB = Accumulate[linedataA];

ListLinePlot[{linedataA, linedataB},
 Frame -> {{True, False}, {True, False}},
 FrameLabel ->
   Map[Style[#, {FontFamily -> "Courier", 13}] &,
   {"Simulation Step", "Price"}],
 PlotLegends -> {"Set A", "Set B"}]

enter image description here

You might find this book useful: Mathematica Navigator. It shows a lot of charting techniques.

share|improve this answer
Thanks Chris! Useful to know. – sebastian c. Jan 16 '13 at 16:55
Hi Chris, what about placing the Mean[List], Max[List] and Min[List] on the histogram (or ListLinePlot) that I already calculated? At the moment they are simply outputs somewhere else. – sebastian c. Jan 19 '13 at 14:34
Hi Chris, could you show how to overlay histogram simulations a and b together? I tried plot1=Labeled[Histogram[data...]], plot2=Labeled[Histogram[data...]], and then Show[plot1, plot2] doesnt work? Error:Labeled is not a Graphics primitive or directive. – sebastian c. Jan 20 '13 at 1:32
Hi Chris, Thanks very cool, but not sure the difference between the two from the histograms? Dont see where you define the histogram colors and thickness? By ColorData? – sebastian c. Jan 20 '13 at 13:19
ChartLegends is not an option for ListLinePlot? Tried applying the Histogram example for ListLinePlot but returns-> Unknown option ChartLegends? – sebastian c. Jan 20 '13 at 16:43

This can be accomplished by a combination of two options: Frame and FrameLabel.

data = RandomReal[10, {10, 2}];
ListPlot[data, FrameLabel -> {"x", "y"}, Frame -> {{True, False}, {True, False}}]

enter image description here

As shown above, FrameLabels by itself does not do it as you need to specify which sides of the frame are displayed. Note, this applies to all two dimensional plots.

share|improve this answer
Thanks @rcollyer, though the FrameLabel looks small, any way set FontSize? But applying it on the Histogram I noticed the whole set of data gets shifted up so data seems to be floating instead of where it was before? Histogram[Table[zcb[i],{i,mcRunHJM}],FrameLabel-> {"Price","Relative Frequency"},Frame-> {True, True, False, False}] – sebastian c. Jan 16 '13 at 16:19
@sebastianc. LabelStyle. Also, if this is useful to you, you should vote for it. If it solves your problem, you should accept it. I'd suggest accepting only after a period of time (like 24 hours) to allow for other answers to come in. – rcollyer Jan 16 '13 at 16:23
@BrettChampion both forms work, at least in 8. – rcollyer Jan 16 '13 at 16:40
Yes, both forms work, but I'd rather people learn to use the "new" (introduced in V6) syntax rather than the older syntax. – Brett Champion Jan 16 '13 at 17:41

I like to use the frame method for histograms as well as for plots. To stop it shifting up the you can set PlotRangePadding to None for the relevant side. In addition, if manually setting the chart range, you can turn off the y-axis to avoid a nasty line in your histogram marking the first bin. Finally, I change the font settings using BaseStyle.

Histogram[RandomReal[NormalDistribution[0, 1], 200],
  Frame -> {True, True, False, False},
  FrameLabel -> {"Price", "Frequency"},
  PlotRangePadding->{Automatic, {None, Automatic}},
  BaseStyle -> {FontSize -> 14},
  PlotRange -> {{-5, 5}, Automatic}, Axes -> {True, False}]


Histogram with sensible axis label positions

share|improve this answer

Your Answer


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.