4
$\begingroup$
SeedRandom[1];
RandomVariate[NormalDistribution[], 100];
Histogram[%, Automatic, "Probability"]

The above code produces a histogram like

enter image description here

I want to translate the figure by say $\{1,1\}$ as follows:

enter image description here

Can someone help me do this?

$\endgroup$
7
$\begingroup$

Update: An alternative approach is to use ChartElementFunction:

Histogram[data, Automatic, "Probability", ChartStyle -> "Rainbow",
 ChartElementFunction -> (ChartElementDataFunction["GlassRectangle"][1 + #, ##2] &),
 AxesOrigin -> {-3, 1}, PlotRange -> All]

enter image description here


Original post:

SeedRandom[1];
data = RandomVariate[NormalDistribution[], 100];
hist = Histogram[data, Automatic, "Probability"]

Show[MapAt[Translate[#, {1, 1}] &, hist, {1}], 
 AxesOrigin -> {-3, 1}, PlotRange -> {{-3, 4}, {1, 1.5}}]

enter image description here

Alternatively, post-process Rectangles:

Show[hist /. RectangleBox[{x0_, y0_}, {x1_, y1_}, z___] :> 
             RectangleBox[1 + {x0, y0}, 1 + {x1, y1}, z],
 AxesOrigin -> {-3, 1}, PlotRange -> {{-3, 4}, {1, 1.5}}]
(* same picture *)
$\endgroup$
  • $\begingroup$ Thank you, this exactly what i needed $\endgroup$ – user13892 Apr 15 '15 at 21:36
  • $\begingroup$ @user13892, my pleasure. Welcome to mma.se. $\endgroup$ – kglr Apr 15 '15 at 21:37
1
$\begingroup$

You could just re-write the Ticks:

Histogram[mydata, Automatic, "Probability", 
 Ticks -> {{#, # + 1, {0.015, 0}} & /@  Range[-3, 3], 
           {#, # + 1, {0.015, 0}} & /@ Range[0, 0.35, 0.05]}]

enter image description here

Minor ticks are left as an exercise for the reader.

$\endgroup$
0
$\begingroup$

To shift left-to-right, merely add $1$ to each sampled point:

SeedRandom[1];
1 + #& /@ RandomVariate[NormalDistribution[], 100];
Histogram[%, Automatic, "Probability"]

If one lists the vertical axis as "probability," then surely one doesn't want to add $1$ to each abscissa value as that would violate the definition of a probability measure.

$\endgroup$
  • $\begingroup$ This doesn't add $1$ to vertical axis. $\endgroup$ – Mahdi Apr 15 '15 at 21:24

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.