3
$\begingroup$

By default, Mathematica plots follow the universal convention of making the abscissa (aka x) horizontal and the ordinate (aka y) vertical.

Some plot types, however, allow one to specify a different convention. For example, the following produces a histogram with a vertical abscissa and a horizontal ordinate:

Histogram[
 BlockRandom[SeedRandom[0]; 
  RandomVariate[NormalDistribution[0, 1], 1000]],
 BarOrigin -> Left]

Mathematica graphics

BarOrigin, however, is not a valid SmoothHistogram option.

What is the SmoothHistogram analogue of the Histogram expression above?


(I am primarily interested in solutions that do not involve rasterizing the plot and rotating the resulting image.)


More generally, how does one plot a function such that the abscissa increases, say, in the upwards vertical direction, and the ordinate increases, say, from left to right?

$\endgroup$
  • 1
    $\begingroup$ If no such analogue option exists, a possible workaround is to use SmoothKernelDistribution: z = RandomVariate[NormalDistribution[0, 1], 100]; pdf = Table[PDF[SmoothKernelDistribution[z], x], {x, -4, 4, 0.01}]; ListPlot[Transpose[{pdf, Table[x, {x, -4, 4, 0.01}]}], Joined -> True]. $\endgroup$ – JimB May 11 '17 at 15:15
  • 1
    $\begingroup$ ...or, use ParametricPlot[]. $\endgroup$ – J. M. will be back soon May 11 '17 at 15:18
3
$\begingroup$

Perhaps you can use SmoothKernelDistribution and ContourPlot. First the distribution:

dist = SmoothKernelDistribution @ BlockRandom[
    SeedRandom[0];
    RandomVariate[NormalDistribution[0,1],1000]
];

Then, use ContourPlot to visualize:

ContourPlot[PDF[dist, y] == x, {x, 0, .5}, {y, -3.5, 5}, Frame->False, Axes->True]

enter image description here

$\endgroup$
3
$\begingroup$

You can also post-process SmoothHistogram output using ReflectionTransform:

reflectF = Graphics[#[[1]] /. ll : (_Line | _Polygon) :> 
     GeometricTransformation[ll, ReflectionTransform[{1, -1}]], 
    Axes -> True, AspectRatio -> GoldenRatio] &;

SmoothHistogram[BlockRandom[SeedRandom[0];
   RandomVariate[NormalDistribution[0, 1], {3, 1000}]], 
   PlotStyle -> Thick, Filling -> Bottom] // reflectF

Mathematica graphics

$\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.