I am looking for a way to rotate a plot generated in matplotlib-pyplot (Python libraries) by 45 degrees (so that instead of a square shape you would have a diamond shape, for example), anyone know if this can be done?
One way I can think of is to use a rotation filter on all the data so that it appears rotated, but then the plot itself will still be in the original orientation.
I want to be able to use the matplotlib interactive features, so saving as an image and then rotating won't work.
Also, I want to use pyplot functions to draw the plot, so using a different library for the plotting is not an ideal solution.
Perhaps if you do it on a 3D plot?
http://matplotlib.1069221.n5.nabble.com/How-to-rotate-a-3D-plot-td19185.html
axes3d.view_init(elev, azim)
Have you looked at PIL?
This code will rotate an image. So if you first output the plot to a file as an image, you could then do
This post suggests that you can only do it "by hand".
Based on Bitwise anwer, you can use the following function:
Ok so currently the only partial solution I found is to apply a rotation to the plot. This allows to use the interactive interface that matplotlib/pyplot offers.
For dot plots like plot() and scatter() this is trivial, but I was specifically interested in rotating imshow(). This link discusses the transform keyword that could have potentially been used for this task, but it is apparently not working.
Fortunately, I found a workaround using pcolormesh(). pcolormesh() plots a quadrilateral mesh and allows you to specify the corner coordinates. So, the answer is to just apply the relevant transformations to the corner coordinates. Note however, that pcolormesh() works a bit different than imshow - it plots your matrix flipped.
I haven't seen this solution anywhere on the web, so here is some code for pcolormesh()/imshow() rotated by 45 degrees: