如何从 anxn 矩阵生成等值线图?
我有一个名为 o_pottial
的 xn 矩阵,其中填充了一些值,并希望从中生成等值线图。我尝试了几种方法但没有成功。这就是我现在所拥有的。
n = 20
x = arange(0,n-1)
y = arange(0,n-1)
plt.contourf(x, y, o_potential[x][y])
plt.show()
o_pottial
看起来像这样
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. ]]
我收到以下错误消息:“用作索引的数组必须是整数(或布尔)类型。”
从昨天开始我就一直在为此苦苦挣扎。我尝试了几乎所有的Google结果,但无法解决问题。感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
或者只是
很难确切地说问题是什么,因为您没有显示 o_pottial,但上面的方法可能会起作用。
Try:
or just
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: