I'm trying a create a plot with two types of plots on top of each other: pyplot.spy
over pyplot.imshow
. Since spy plots a sparse matrix, I want it to be transparent where the matrix has zeros. However, when I plot the sparse matrix on the same axis, it seems to be creating a new canvas covering the one created by imshow.
Here's a description of my steps. Note that I'm using spy in the marker style, which returns a Line2D object.
A
: array of size m*n
B
: array of size m*n
where most elements are 0s(rest are 1s)
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
p1 = ax.imshow(A, aspect='auto')
p2 = ax.spy(B, aspect = 'auto', markersize=2, alpha = 0.25)
plt.show()
I'd appreciate suggestions and help.