Skip to content

Instantly share code, notes, and snippets.

@Phlya
Created June 17, 2019 08:55
Show Gist options
  • Save Phlya/e2441d9d126204d247fe41dca5f3e804 to your computer and use it in GitHub Desktop.
Save Phlya/e2441d9d126204d247fe41dca5f3e804 to your computer and use it in GitHub Desktop.
def pcolormesh_45deg(matrix_c, ax, start=0, resolution=1, *args, **kwargs):
start_pos_vector = [start+resolution*i for i in range(len(matrix_c)+1)]
import itertools
n = matrix_c.shape[0]
t = np.array([[1, 0.5], [-1, 0.5]])
matrix_a = np.dot(np.array([(i[1], i[0])
for i in itertools.product(start_pos_vector[::-1],
start_pos_vector)]), t)
x = matrix_a[:, 1].reshape(n + 1, n + 1)
y = matrix_a[:, 0].reshape(n + 1, n + 1)
im = ax.pcolormesh(x, y, np.flipud(matrix_c), *args, **kwargs)
im.set_rasterized(True)
return im
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment