- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图在曲线网格上绘制流线,但我遇到了错误,为此:
/usr/local/lib/python2.7/dist-packages/matplotlib/streamplot.pyc in streamplot(axes, x, y, u, v, density, linewidth, color, cmap, norm, arrowsize, arrowstyle, minlength, transform)
100
101 ## Sanity checks.
--> 102 assert u.shape == grid.shape
103 assert v.shape == grid.shape
104
AssertionError:
我做了 matplotlib 示例,它运行良好。我如何绘制流线到这个网格?代码在这里,你可以试试。这对我来说真的很重要。
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
xx = np.array([[-32.77352506, -32.50517324, -32.30341846, -32.12060867, -31.99103968],
[-32.88670112, -32.63078693, -32.42892793, -32.2527705 , -32.11911059],
[-32.99884749, -32.75419286, -32.55377179, -32.38220417,-32.24664094],
[-33.10888993, -32.87495033, -32.67707405, -32.50885765,-32.37311971],
[-33.2179889 , -32.99317728, -32.79848554, -32.63304009,-32.49815164],
[-33.32651265, -33.10917094, -32.91791567, -32.75496914,-32.62146004],
[-33.43449219, -33.22321261, -33.03537769, -32.87477271,-32.74286757],
[-33.54184645, -33.33551502, -33.15092328, -32.99252837,-32.86227065],
[-33.64847256, -33.44622558, -33.26461466, -33.1082882 ,-32.97961644],
[-33.7542787 , -33.55544297, -33.37651245, -33.22209182,-33.09488502],
[-33.85919362, -33.66323316, -33.48667092, -33.33397251,-33.20807667],
[-33.96316738, -33.76964127, -33.59513666, -33.44395994,-33.31920308],
[-34.06616899, -33.87469962, -33.70194888, -33.55208114,-33.42828168],
[-34.16818354, -33.97843289, -33.80714029, -33.6583608 , -33.5353318 ],
[-34.26920936, -34.08086103, -33.91073804, -33.76282129,-33.64037232],
[-34.36925566, -34.18200076, -34.01276449, -33.86548266,-33.74342012],
[-34.46834041, -34.28186594, -34.11323791, -33.96636282,-33.84448915],
[-34.56648851, -34.38046701, -34.21217281, -34.06547784,-33.94358994],
[-34.66372971, -34.4778096 , -34.30958029, -34.16284263, -34.0407292 ],
[-34.76009619, -34.57389229, -34.40546833, -34.2584719 ,-34.13590974],
[-34.85561889, -34.66870332, -34.49984222, -34.35238178,-34.22913045],
[-34.95032165, -34.76221629, -34.59270529, -34.44459209,-34.32038648],
[-35.04421102, -34.85438466, -34.6840602 , -34.5351297 ,-34.40966975],
[-35.13725786, -34.94513595, -34.77391107, -34.62403315,-34.49697031],
[-35.22936336, -35.03436723, -34.86226647, -34.7113589 , -34.5822793 ],
[-35.3202956 , -35.12194712, -34.9491432 , -34.79718943,-34.66559567],
[-35.40957149, -35.20773648, -35.03457067, -34.88164276,-34.74693998],
[-35.49624617, -35.29165455, -35.11859869, -34.96488179,-34.82637986],
[-35.57858891, -35.3738341 , -35.20134195, -35.04711944,-34.90406862],
[-35.65407127, -35.45484625, -35.28327484, -35.12861303,-34.98028311]])
yy = np.array([[-11.3529916 , -10.83017948, -10.36062676, -9.85499224,-9.36742115],
[-11.24914312, -10.77486528, -10.30767657, -9.81790781,-9.33347811],
[-11.16896123, -10.71827884, -10.25654788, -9.77873607,-9.29985941],
[-11.09864806, -10.66157581, -10.20688907, -9.7389486 ,-9.26669158],
[-11.03379175, -10.60554773, -10.15836065, -9.69919353, -9.2340536 ],
[-10.97234269, -10.55056628, -10.11076275, -9.65973621,-9.20197376],
[-10.91318741, -10.49672964, -10.06398502, -9.62068888,-9.17044015],
[-10.85567682, -10.44399733, -10.01795592, -9.58209354,-9.13941538],
[-10.79941292, -10.39227109, -9.97261586, -9.54395471,-9.10884902],
[-10.74413933, -10.3414354 , -9.92790608, -9.50625469,-9.07868586],
[-10.68968138, -10.29137538, -9.88376528, -9.46896173,-9.04887037],
[-10.63591212, -10.24198327, -9.84012944, -9.43203502,-9.01934878],
[-10.58273238, -10.19315956, -9.79693259, -9.39542787,-8.99006955],
[-10.53005851, -10.14481189, -9.75410767, -9.35908973,-8.96098324],
[-10.47781454, -10.09685326, -9.71158727, -9.32296761,-8.93204187],
[-10.42592671, -10.04920008, -9.66930413, -9.28700687,-8.90319822],
[-10.37431922, -10.00177041, -9.62719161, -9.25115173, -8.874405 ],
[-10.32291042, -9.95448254, -9.5851842 , -9.21534553,-8.84561388],
[-10.27160885, -9.90725399, -9.54321824, -9.17953081, -8.8167744 ],
[-10.22030865, -9.86000117, -9.50123304, -9.1436493 ,-8.78783251],
[-10.16888358, -9.81263985, -9.45917264, -9.10764179,-8.75872859],
[-10.11717908, -9.7650871 , -9.41698825, -9.07144794,-8.72939466],
[-10.06500151, -9.71726547, -9.37464171, -9.03500603,-8.69975035],
[-10.01210356, -9.66911062, -9.33211024, -8.99825263,-8.66969694],
[ -9.95816574, -9.62058406, -9.28939255, -8.96112225, -8.639109 ],
[ -9.90277604, -9.57169217, -9.24651752, -8.92354679,-8.60782312],
[ -9.84541584, -9.52250952, -9.2035585 , -8.88545441,-8.57562469],
[ -9.78546516, -9.4731919 , -9.1606645 , -8.84676681,-8.54223813],
[ -9.72217224, -9.42392909, -9.11814094, -8.80739381,-8.50733329],
[ -9.65407127, -9.37474785, -9.07654968, -8.76722606,-8.47056622]])
u = 1/2*np.sin(xx)*-3*np.cos(yy**2)
v = 2*np.sin(xx)*3*np.cos(yy)
speed = np.sqrt((u**2)+(v**2))
plt.ion()
fig,(ax1,ax2) = plt.subplots(1,2)
m = Basemap(llcrnrlon=xx.min(),llcrnrlat=yy.min(),
urcrnrlon=xx.max(), urcrnrlat=yy.max(),
projection='merc',resolution='i',ax=ax1)
m.drawcoastlines()
m.drawcountries()
m.fillcontinents(color='0.86')
m.contourf(xx,yy,speed,latlon=True)
m.plot(xx,yy,'-k',alpha=0.3,latlon=True)
m.plot(xx.T,yy.T,'-k',alpha=0.3,latlon=True)
m.quiver(xx,yy,u,v,latlon=True)
m2 = Basemap(llcrnrlon=xx.min(),llcrnrlat=yy.min(),
urcrnrlon=xx.max(), urcrnrlat=yy.max(),
projection='merc',resolution='i',ax=ax2)
m2.drawcoastlines()
m2.drawcountries()
m2.fillcontinents(color='0.86')
m2.contourf(xx,yy,speed,latlon=True)
m2.plot(xx,yy,'-k',alpha=0.3,latlon=True)
m2.plot(xx.T,yy.T,'-k',alpha=0.3,latlon=True)
m2.streamplot(xx,yy,u,v)
最佳答案
这个函数解决的问题:
from scipy.interpolate import griddata
def streams(ax,xx,yy,u,v,base_map=False):
x = np.linspace(xx.min(), xx.max(), 50)
y = np.linspace(yy.min(), yy.max(), 50)
xi, yi = np.meshgrid(x,y)
#then, interpolate your data onto this grid:
px = xx.flatten()
py = yy.flatten()
pu = u.flatten()
pv = v.flatten()
pspeed = speed.flatten()
gu = griddata(zip(px,py), pu, (xi,yi))
gv = griddata(zip(px,py), pv, (xi,yi))
gspeed = griddata(zip(px,py), pspeed, (xi,yi))
lw = 6*gspeed/np.nanmax(gspeed)
#now, you can use x, y, gu, gv and gspeed in streamplot:
if base_map:
xx,yy = ax(xx,yy)
xi,yi = ax(xi,yi)
ax.contour(xx,yy,speed, colors='k', alpha=0.4)
ax.plot(xx,yy,'-k',alpha=0.3)
ax.plot(xx.T,yy.T,'-k',alpha=0.3)
ax.plot(xi,yi,'-b',alpha=0.1)
ax.plot(xi.T,yi.T,'-b',alpha=0.1)
c = ax.streamplot(x,y,gu,gv, density=2,
linewidth=lw, color=gspeed, cmap=plt.cm.jet)
关于python - 不均匀(曲线)网格的 Matplotlib 流图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25297375/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!