0
$\begingroup$

I have an issue where my y axis is drawn too far down. I feel like there should be a question out there asking about this, but I wasn't able to find anything. Is there any way to make the y-axis only draw so that it makes a perfect L shape with the x axis?

Here is my code:

flux[t_] := 
   Sqrt[2/π] (8 + 6 t) Exp[-2*(6 - 2 t)^2/(4 + t^2)]
   /(4 + t^2)^(3/2);

fluxPlot = Plot[flux[t], {t, tMin - dt, tMax + dt},
   PlotStyle -> {Thickness[0.0090], GrayLevel[0], Opacity[0.8]},
   LabelStyle -> Opacity[0],
   Ticks -> None
   ];

h = Histogram[histPoints, {dt}, "ProbabilityDensity",
   ChartStyle -> GrayLevel[0.88, opacityHist],
   ChartBaseStyle -> EdgeForm[Opacity[opacityHist + 0.15]],
   LabelStyle -> Opacity[0],
   Ticks -> None,
   AxesStyle -> Thickness[0.006]
   ];

Show[h,fluxPlot]

And here is the issue, visible in the bottom left corner below the x-axis:

enter image description here

$\endgroup$
  • $\begingroup$ Add the option PlotRangePadding -> 0? $\endgroup$ – kglr Apr 5 at 1:22
  • 1
    $\begingroup$ what is flux? $\endgroup$ – Pillsy Apr 5 at 1:27
  • $\begingroup$ Adding PlotRangePadding -> 0 removed the entire y axis. I have edited in the flux function now. $\endgroup$ – doublefelix Apr 5 at 1:29
  • $\begingroup$ Update: I was able to fix it by making PlotRangePadding = {0.126, 0.003}. These values were found by just guessing and checking... going too far made the whole axis disappear but not going far enough left that little notch on the bottom. I don't know if there's a more elegant solution or not $\endgroup$ – doublefelix Apr 5 at 1:41
2
$\begingroup$
hstpts = RandomVariate[LogNormalDistribution[1, 1], 1500];
flx[x_] := PDF[LogNormalDistribution[1, 1], x];

plt = Plot[flx[x], {x, 0, 20}, PlotStyle -> Red];
hist = Histogram[hstpts, Automatic, "PDF"];

Show[plt, hist, plt, PlotRangePadding -> 0]

enter image description here

Alternatively, use the first Part of hist as Prolog in Plot:

Plot[flx[x], {x, 0, 20}, PlotStyle -> Red, PlotRangePadding -> 0, 
 Prolog -> First @ hist] 

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Had to mess around a bit with PlotRangePadding -> {xPadding, yPadding} but ultimately it was the solution :) $\endgroup$ – doublefelix Apr 5 at 2:12

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.