1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > java绘等高线图_Matplotlib中的极坐标等高线图

java绘等高线图_Matplotlib中的极坐标等高线图

时间:2018-09-13 04:56:13

相关推荐

java绘等高线图_Matplotlib中的极坐标等高线图

Matplotlib的 contour() 函数要求将数据排列为点的2D网格以及每个网格点的相应网格值 . 如果您的数据自然排列在网格中,您可以将r,theta转换为x,y并使用 contour(r*np.cos(theta), r*np.sin(theta), values) 来制作您的绘图 .

如果您的数据不是't naturally gridded, you should follow Stephen'的建议,并使用 griddata() 将数据插入到网格中 .

以下脚本显示了两者的示例 .

import pylab as plt

from matplotlib.mlab import griddata

import numpy as np

# data on a grid

r = np.linspace(0, 1, 100)

t = np.linspace(0, 2*np.pi, 100)

r, t = np.meshgrid(r, t)

z = (t-np.pi)**2 + 10*(r-0.5)**2

plt.subplot(121)

plt.contour(r*np.cos(t), r*np.sin(t), z)

# ungrid data, then re-grid it

r = r.flatten()

t = t.flatten()

x = r*np.cos(t)

y = r*np.sin(t)

z = z.flatten()

xgrid = np.linspace(x.min(), x.max(), 100)

ygrid = np.linspace(y.min(), y.max(), 100)

xgrid, ygrid = np.meshgrid(xgrid, ygrid)

zgrid = griddata(x,y,z, xgrid, ygrid)

plt.subplot(122)

plt.contour(xgrid, ygrid, zgrid)

plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。