26 Sep 19:38
spy: ignore zero values in sparse matrix
From: Tony S Yu <tonyyu@...>
Subject: spy: ignore zero values in sparse matrix
Newsgroups: gmane.comp.python.matplotlib.devel
Date: 2008-09-26 17:39:51 GMT
Subject: spy: ignore zero values in sparse matrix
Newsgroups: gmane.comp.python.matplotlib.devel
Date: 2008-09-26 17:39:51 GMT
When sparse matrices have explicit zero values, `axes.spy` plots those
zero values. This behavior seems unintentional. For example, the
following code should have a main diagonal with markers missing in the
middle, but `spy` currently plots a full main diagonal.
#~~~~~~~~~~~
import scipy.sparse as sparse
import matplotlib.pyplot as plt
sp = sparse.spdiags([[1,1,1,0,0,0,1,1,1]], [0], 9, 9)
plt.spy(sp, marker='.')
#~~~~~~~~~~~
Below is a patch which only plots the nonzero entries in a sparse
matrix. Note, sparse matrices with all zero entries raises an error;
this behavior differs from dense matrices. I could change this
behavior, but I wanted to minimize the code changed.
Cheers,
-Tony
PS: this patch also includes two trivial changes to some examples.
Index: lib/matplotlib/axes.py
===================================================================
--- lib/matplotlib/axes.py (revision 6122)
+++ lib/matplotlib/axes.py (working copy)
@@ -6723,9 +6723,11 @@
else:
(Continue reading)
RSS Feed