SeedRandom[1];
RandomVariate[NormalDistribution[], 100];
Histogram[%, Automatic, "Probability"]
The above code produces a histogram like
I want to translate the figure by say $\{1,1\}$ as follows:
Can someone help me do this?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communitySeedRandom[1];
RandomVariate[NormalDistribution[], 100];
Histogram[%, Automatic, "Probability"]
The above code produces a histogram like
I want to translate the figure by say $\{1,1\}$ as follows:
Can someone help me do this?
Update: An alternative approach is to use ChartElementFunction
:
Histogram[data, Automatic, "Probability", ChartStyle -> "Rainbow",
ChartElementFunction -> (ChartElementDataFunction["GlassRectangle"][1 + #, ##2] &),
AxesOrigin -> {-3, 1}, PlotRange -> All]
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}}]
Alternatively, post-process Rectangle
s:
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 *)
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.
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]}]
Minor ticks are left as an exercise for the reader.