So, I'm trying to make a graph with different colored squares where each one is colored according to the probability stored in my csc_matrix nprob, which is 7x7. The x and y in my graph are just supposed to be the place in the matrix.
nprob = prob/sum
print(nprob.todense())
i=[0,1,2,3,4,5,6]
j=[0,1,2,3,4,5,6]
print(nprob[i,j])
x,y = np.meshgrid(np.arange(0,7,1),np.arange(0,7,1))
z,zx,zy=nprob[i,j],i,j
fig, dens = plt.subplots()
dens.set_title('probability density for...')
dens.set_xlabel('i')
dens.set_ylabel('t')
m = dens.pcolormesh(i, j, z, cmap = 'Blues', shading='auto')
cbar=plt.colorbar(m)
When I print nprob[i,j] I'm just getting nprob[0,j] (first row of the matrix) and I don't know why. That's probably the crux of my issue (I can also choose any integer for i and get just that row of the matrix, but I'm wanting to get all the rows denoted by the list i). I also get my empty graph. So I think my question is, why are the dimensions of my 7x7 matrix just 1x7 when I call it with variables? Here's the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-87-f3876b8770bc> in <module>
13 dens.set_xlabel('i')
14 dens.set_ylabel('t')
---> 15 m = dens.pcolormesh(i, j, z, cmap = 'Blues', shading='auto')
16 cbar=plt.colorbar(m)
/opt/miniconda3/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
1445 def inner(ax, *args, data=None, **kwargs):
1446 if data is None:
-> 1447 return func(ax, *map(sanitize_sequence, args), **kwargs)
1448
1449 bound = new_sig.bind(ax, *args, **kwargs)
/opt/miniconda3/lib/python3.8/site-packages/matplotlib/axes/_axes.py in pcolormesh(self, alpha, norm, cmap, vmin, vmax, shading, antialiased, *args, **kwargs)
6090 kwargs.setdefault('edgecolors', 'None')
6091
-> 6092 X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
6093 shading=shading, kwargs=kwargs)
6094 Ny, Nx = X.shape
/opt/miniconda3/lib/python3.8/site-packages/matplotlib/axes/_axes.py in _pcolorargs(self, funcname, shading, *args, **kwargs)
5609 if shading == 'flat':
5610 if not (ncols in (Nx, Nx - 1) and nrows in (Ny, Ny - 1)):
-> 5611 raise TypeError('Dimensions of C %s are incompatible with'
5612 ' X (%d) and/or Y (%d); see help(%s)' % (
5613 C.shape, Nx, Ny, funcname))
TypeError: Dimensions of C (1, 7) are incompatible with X (7) and/or Y (7); see help(pcolormesh)
question from:
https://stackoverflow.com/questions/65865018/why-does-my-matrix-with-variable-indices-include-only-the-first-row