12
$\begingroup$

I have a such graphic:

data = {{0, 5}, {1.9, 7.5}, {0, 12}, {-5, 15.5}, {-1.2, 33.4}};
p=Plot[Interpolation[Reverse /@ data, x, InterpolationOrder -> 2], {x, 
  0, 55}, Epilog -> {Red, PointSize[.01], Point[Reverse /@ data]}]

But acutually this picture is expected(except that ticks label rotated)

Note the interpolation method should be used,but not the fit method here.How to get such graphic?


Update:

I get a lot solution in following answers.But I realize if I have a option Filling -> Axis in my p.All solution cannot work anymore.

$\endgroup$
1

4 Answers 4

14
$\begingroup$
p = Plot[Interpolation[Reverse /@ data, x, InterpolationOrder -> 2], {x, 0, 55}, 
         Epilog -> {Red, PointSize[.01], Point[Reverse /@ data]}, Filling -> Axis]

You can post-process p to rotate the graphics primitives:

Show[Normal[p] /. prim : _Line | _Point | _Polygon :> 
   GeometricTransformation[prim, RotationTransform[Pi/2]], 
 PlotRange -> All, AspectRatio -> GoldenRatio]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Congratulation for 100K. :) And I realize if we have a option Filling -> Axis in p.The rotate graphic cannot include anymore? $\endgroup$
    – yode
    Commented Jan 14, 2017 at 23:35
  • $\begingroup$ Thank you @yode. Please the new version to deal with Filling. $\endgroup$
    – kglr
    Commented Jan 15, 2017 at 1:52
9
$\begingroup$

This is pretty neat:

data = {{0, 5}, {1.9, 7.5}, {0, 12}, {-5, 15.5}, {-1.2, 33.4}};
iFun = Interpolation[Reverse[data, 2], InterpolationOrder -> 2];
ParametricPlot[Cross[{x, iFun[x]}], {x, 0, 55}, AspectRatio -> GoldenRatio, 
               Epilog -> {Directive[Red, PointSize[.01]],
                          Point[Cross /@ Reverse[data, 2]]}]

rotated plot

I'll leave fiddling with the ticks up to you.

$\endgroup$
6
$\begingroup$
data = {{0, 5}, {1.9, 7.5}, {0, 12}, {-5, 15.5}, {-1.2, 33.4}};
plot = Plot[
   Interpolation[Reverse /@ data, x, InterpolationOrder -> 2], {x, 0, 
    55}, Epilog -> {Red, PointSize[.01], Point[Reverse /@ data]}];


Graphics[
   Rotate[{#, Epilog /. {##2}}, Pi/2, {0, 0}], 
   AspectRatio -> GoldenRatio, Axes -> True
] & @@ plot

enter image description here

$\endgroup$
4
$\begingroup$

For your updated example:

data = {{0, 5}, {1.9, 7.5}, {0, 12}, {-5, 15.5}, {-1.2, 33.4}};

p = Plot[Interpolation[Reverse /@ data, x, InterpolationOrder -> 2], {x, 0, 55}, 
  Epilog -> {Red, PointSize[.01], Point[Reverse /@ data]}, Filling -> Axis]

A variation of axisFlip from How can I transpose x and y axis on a Plot? and Plot time along the y-axis?

axisRotate = # /. {x_Point | x_Line | x_GraphicsComplex :> 
      MapAt[(#.{{0, 1}, {-1, 0}}) &, x, 1]} &;

Show[axisRotate@p, AspectRatio -> GoldenRatio/1, PlotRange -> All]

enter image description here

Tick labels still show negative values however. If we are going to fiddle with tick labels another approach opens up: just counter-rotate the labels:

rR = {#, Rotate[#, -90 °]} &;

Show[p, Ticks -> {rR /@ Range[10, 50, 10], rR /@ Range[20, 60, 20]}] // 
 Rotate[#, 90 °] &

enter image description here

This is not as nice for further processing and use so I favor the first method.

$\endgroup$
8
  • 1
    $\begingroup$ An alternative is to use GeometricTransformation, as in: p /. Graphics[g_, r___] :> Graphics[GeometricTransformation[g, RotationTransform[Pi/2]], PlotRange -> All, AspectRatio -> GoldenRatio, r] $\endgroup$
    – Carl Woll
    Commented Jan 15, 2017 at 0:38
  • $\begingroup$ @CarlWoll That certainly could be useful for more complicated transformations, but is there any advantage in this case over Dot? $\endgroup$
    – Mr.Wizard
    Commented Jan 15, 2017 at 0:39
  • 1
    $\begingroup$ It is useful because you don't have to have consider every possible Graphics primitive, e.g., Arrow, Polygon, etc. The OP example only has Point and Line, so using explicit rules for these objects works just as well. $\endgroup$
    – Carl Woll
    Commented Jan 15, 2017 at 0:53
  • $\begingroup$ @CarlWoll I overlooked that part of your code entirely. Thanks! $\endgroup$
    – Mr.Wizard
    Commented Jan 15, 2017 at 0:55
  • $\begingroup$ @CarlWoll Your method misses the Epilog graphics which is undesirable for the example at hand. What solution do you propose for that? One could target Epilog expressly but I wonder if there is a more general way in the spirit of that replacement rule. $\endgroup$
    – Mr.Wizard
    Commented Jan 15, 2017 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.