python - 这个匀称的错误信息有什么问题
问题描述
我有一个名为 Rsize 的字典,其中有 number-List 作为键值对。字典是这样的
{10: [0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017], 12: [0.6638977494825118, 0.663295576452323, 0.662262804664348, 0.6610413916318628, 0.6590939627030634, 0.655212304186114, 0.6492141689834672, 0.6380632834031537, 0.6096663492242224, 0.5647498006858608, 0.4983281599318278, 0.3961350546063216, 0.32119092575707087, 0.2257230704567207, 0.1816695139119151, 0.14363448808684576], 14: [0.6649598494971014, 0.6644370245269158, 0.6638578972784479, 0.6630511299276417, 0.6615070373022596, 0.6596206155163766, 0.6560628158033714, 0.6487119276511941, 0.6343385358239866, 0.5792725000508062, 0.49799837531709923, 0.42482204326408324, 0.26633662071414366, 0.2028085235063155, 0.12411214668987203, 0.09336935548451253]}
[0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017]
键是 10、14、16。我已使用每个列表进行绘图,并希望找出它们的成对交点。我为此编写了以下脚本,并使用形状相交函数进行交叉点检测。
from shapely.geometry import LineString
Rsize={10: [0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017], 12: [0.6638977494825118, 0.663295576452323, 0.662262804664348, 0.6610413916318628, 0.6590939627030634, 0.655212304186114, 0.6492141689834672, 0.6380632834031537, 0.6096663492242224, 0.5647498006858608, 0.4983281599318278, 0.3961350546063216, 0.32119092575707087, 0.2257230704567207, 0.1816695139119151, 0.14363448808684576], 14: [0.6649598494971014, 0.6644370245269158, 0.6638578972784479, 0.6630511299276417, 0.6615070373022596, 0.6596206155163766, 0.6560628158033714, 0.6487119276511941, 0.6343385358239866, 0.5792725000508062, 0.49799837531709923, 0.42482204326408324, 0.26633662071414366, 0.2028085235063155, 0.12411214668987203, 0.09336935548451253]}
[0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017]
listkT = np.arange(4.0,4.8,0.05)
print(Rsize[10])
plt.figure(figsize=(18, 10))
plt.title ('Binder cumulant for critical point')
plt.plot(listkT, Rsize[10], '-',label='Lattice sie 10')
plt.plot(listkT, Rsize[12], '-',label='Lattice sie 12')
plt.plot(listkT, Rsize[14], '-',label='Lattice sie 14')
plt.legend()
plt.show()
curve_10=LineString(np.column_stack((listkT, Rsize[10])))
curve_12=LineString(np.column_stack((listkT, Rsize[12])))
curve_14=LineString(np.column_stack((listkT, Rsize[14])))
intersection12 = curve_10.intersection(curve_12)
intersection14 = curve_10.intersection(curve_14)
plt.plot(*LineString(intersection12).xy, 'o')
plt.plot(*LineString(intersection14).xy, 'o')
x12, y = LineString(intersection12).xy
x14, y = LineString(intersection14).xy
print(np.intersect1d(x12, x14))
print(x12,x14)
但是匀称地抛出一个 AssertionError。
File "C:\Users\Endeavour\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\Users\Endeavour\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "E:/Project/Codes/3D.py", line 118, in <module>
plt.plot(*LineString(intersection12).xy, 'o')
File "C:\Users\Endeavour\Anaconda3\lib\site-packages\shapely\geometry\linestring.py", line 48, in __init__
self._set_coords(coordinates)
File "C:\Users\Endeavour\Anaconda3\lib\site-packages\shapely\geometry\linestring.py", line 97, in _set_coords
ret = geos_linestring_from_py(coordinates)
File "shapely/speedups/_speedups.pyx", line 87, in shapely.speedups._speedups.geos_linestring_from_py
AssertionError
不过,这些图是由 matplotlib 正确绘制的。我第一次使用身材匀称,没有以前的经验。任何帮助都感激不尽。谢谢你。注意:最终目标是获得 3 条曲线的交点。如果没有找到它们最接近的点就足够了。找到任何建议或库函数都会有很大帮助。
先感谢您。
解决方案
在断言错误之后,我检查了shapely/speedups/_speedups.pyx
第87 行。geos_linestring_from_py
函数希望您传递 aLineString
或 a LinearRing
。当我打印你的intersection12
,intersection14
我得到:
POINT (4.503201814825258 0.4917840919384173)
POINT (4.51830999373466 0.4712012116887737)
因此,您正在传递一个Point
实例来创建一个LineString
,这会创建一个 AssertionError。
除了您遇到的错误之外,您的方法也是错误的,因为它假设(1)两条曲线之间会有多个交点,以及(2)三条曲线相交处会有一个绝对点。如果你放大你的情节,你会发现情况并非如此。
红色圆圈对应的是你intersection12
,紫色的是intersection14
。如果您正在寻找一个近似解,也许在这种情况下找到这些点的平均值会有所帮助,但对于每对具有多个交点的更复杂的曲线,也不建议这样做。
推荐阅读
- python - 根据索引对多维数组中的元素求和
- mysql - SQL GROUP BY INNER JOIN 和 COUNT
- php - Laravel 5.2:预期响应代码 220,但得到代码“500”,消息“500 Unrecognized command”
- asp.net-core - 在 Scrutor 中多次使用 AddClasses
- python - 哪个 numpy 索引是副本,哪个是视图?
- javascript - 如果属性与比较值不匹配,如何更改数组中对象属性的值?
- python - pandas 按相同键对分组项目进行过滤
- c# - 在 Clickhouse 客户端中禁用 SQL 日志记录
- python - 我正在尝试使用 CSV 文件中的数据绘制饼图,但出现我不明白的错误
- javascript - 使用 js 添加 html 后标签链接不起作用