I have a n x n matrix called o_potential filled with some values and would like to generate a contour plot out of it. I tried several approaches without any success. This is what I have right now.
n = 20
x = arange(0,n-1)
y = arange(0,n-1)
plt.contourf(x, y, o_potential[x][y])
plt.show()
o_potential looks like this
o_potential = [[ -1., -1., -1., -1., -1. ],
[ 10., 4.12244898, 2.7755102, 4.12244898, 10. ],
[ 10., 5.7755102, 4.24489796, 5.7755102, 10. ],
[ 10., 4.12244898, 2.7755102, 4.12244898, 10. ],
[ -1., -1., -1., -1., -1. ]]
I am getting the following error message: "arrays used as indices must be of integer (or boolean) type."
I have been struggling with this from yesterday. I tried almost all the Google results, but couldn't solve the problem. Your help is appreciated!
Try:
n = 20
x = arange(n)
y = arange(n)
X, Y = meshgrid(x, y)
plt.contourf(X, Y, o_potential)
plt.show()
or just
plt.contourf(o_potential)
plt.show()
It's hard to say exactly what the problem is since you don't show o_potential, but the above will likely work.
You can try this as well:
import matplotlib.pyplot as plt
plt.imshow(o_potential, cmap='viridis')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With