Skip to content

Instantly share code, notes, and snippets.

@lukeolson
Last active July 8, 2019 16:23
Show Gist options
  • Save lukeolson/9710288 to your computer and use it in GitHub Desktop.
Save lukeolson/9710288 to your computer and use it in GitHub Desktop.
matplotlib like color spy
def fastspy(A, ax, cmap=None):
""""
Parameters
----------
A : coo matrix
ax : axis
"""
m, n = A.shape
ax.hold(True)
ax.scatter(A.row, A.col, c=A.data, s=20, marker='s',
edgecolors='none', clip_on=False,
cmap=cmap)
ax.axis('off')
ax.axis('tight')
ax.invert_yaxis()
ax.hold(False)
if __name__ == '__main__':
import scipy.io as io
import matplotlib.pyplot as plt
A = io.loadmat('example.mat')['A'].tocoo()
fig = plt.figure()
ax = fig.add_subplot(111)
fastspy(A, ax)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment