I am rotating a n x n matrix (n = 20, although it could change) 30 degrees rightwards using Matplotlib's transformation methods.
The error shows up because rotation is perfomed from the top and not from the base.
I have tried to inverse the index through np.flip()
or ax.imshow(origin = 'lower')
but it also invert the triangle, so I need to discovered how to set the transformation origin point.
Defintley, this is what I would like to obtain:
Note that the little squares that conforms the diagonal matrix would be turned into triangles. Could this be done? Maybe by an imshow method that returns half a pixel? The rest of the pixeles would stay the same (deformed little squares).
Here is the code for generate the matrix (starting point):
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
matrix = np.random.rand(20,20)
# Generate a boolean matrix (same shape than 'matrix') and select lower triangle values:
condition = np.tril(np.ones((matrix.shape))).astype(np.bool)
triangle = np.where(condition, matrix, np.nan)
fig, ax = plt.subplots(figsize = (8,8))
ax.imshow(triangle, cmap = 'Spectral')
And here is the code trying to rotate it:
im = ax.imshow(matrix, cmap = 'Spectral')
im.set_transform(mtransforms.Affine2D().skew(30, 0) + ax.transData)
ax.plot(transform = trans_data)
I am not using Triangle class of Matplotlib because the ternary diagram is represented througout an interpolation operation, and I want to represent the original matrix values.
I'd really appreciate some one's help. Thank you very much in advance.