4
$\begingroup$

I would like to know if it is possible to carry out a rotation involving the x and y axis (the gridline too) cause I know how to do it with a vector and an arrow but not with the axis.

$\endgroup$
6
  • $\begingroup$ If you want a rotated object for visualization that is not a graphics object Rotate[Plot[x^2, {x, -2, 2}], 45 Degree] $\endgroup$ Commented Dec 1, 2022 at 19:21
  • $\begingroup$ If you want an image : Plot[x^2, {x, -2, 2}] // Image // ImageRotate[#, 45 Degree] & $\endgroup$ Commented Dec 1, 2022 at 19:21
  • $\begingroup$ If you want a graphics object then maybe you would need to construct the plot as a graphics object first. see here for how to extract the ticks. For the curve you can use Plot[x^2, {x, -2, 2}] //Cases[#,_Line,All] & $\endgroup$ Commented Dec 1, 2022 at 19:26
  • $\begingroup$ You can also make a graphics Object from the image with errors using ImageGraphics $\endgroup$ Commented Dec 1, 2022 at 19:27
  • $\begingroup$ Consider as well the 3D graphics solution here $\endgroup$ Commented Dec 1, 2022 at 20:42

1 Answer 1

3
$\begingroup$

Here are two ways to get rotated axes:

  • Using the fifth argument of Inset:

    Graphics[
     Inset[Graphics[{}, Axes -> True], {0, 0}, {0, 0}, {2, 2}, {{1, 1}, {0, 1}}],
     PlotRange -> 1
    ]
    

    enter image description here

    This will shear everything inside the inner Graphics expression. As you can see, even the labels of the axes are sheared.

  • Using AxisObject (new in 12.3):

    Graphics[
     {AxisObject[Line@{{-1, -1}/Sqrt[2], {1, 1}/Sqrt[2]}], 
      AxisObject[Line@{{0, -1}, {0, 1}}]},
     PlotRange -> 1
    ]
    

    enter image description here

    Here, you can directly specify from where to where the axes should point. Only the direction of the axes is affected. As you can see, labels of the axes are not affected.

$\endgroup$
2
  • $\begingroup$ Thank you, your comment has been very useful to me. Just one more thing, is this possible tu with manipulate so you can rotate the axis like that??? $\endgroup$ Commented Dec 4, 2022 at 17:59
  • $\begingroup$ With the AxisObject approach, you should be able to add interactivity just as if you had a normal line, e.g. Manipulate[Graphics[{AxisObject[Line@{{0, 0}, Dynamic@p}]}, PlotRange -> 1], {{p, {1, 1}}, Locator}] $\endgroup$
    – Lukas Lang
    Commented Dec 4, 2022 at 21:37

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.