小编Léo*_*ard的帖子

使用Python进行Sublime Text的进度条

我在MacOSX上使用强大的Sublime Text 3编辑器来运行python代码.我想显示for循环的进度条,以及以下命令:

sys.stdout.write('\rProgress : %03.2f %%' % (100*float(i)/(N)))
sys.flush()
Run Code Online (Sandbox Code Playgroud)

不会按预期(\r)清除输出窗口中先前打印的行但生成N行:

Progress : 0.25 %
Progress : 0.50 %
Progress : 0.75 %
Progress : 1.00 %
Progress : 1.25 %
Progress : 1.50 %
Progress : 1.75 %
Progress : 2.00 %
Progress : 2.25 %
Progress : 2.50 %
...
Run Code Online (Sandbox Code Playgroud)

这不是很好读 - 我得出结论,输出窗口可能是只读的.

有没有人建议改善Sublime Text中进度条的使用?

python sublimetext progress-bar sublimetext3

9
推荐指数
4
解决办法
1597
查看次数

Matplotlib 重用由另一个脚本创建的图形

我在 MacOS 上使用 Matplotlib 和 Slime Text。我使用Python 3.5Matplotlib 2.0

当我处理图形时,我通常有一个脚本来绘制数据,并将图形保存在一个 .pdf 文件中,扩展名为 .pdf 文件plt.savefig()。然后我使用Skim(pdf 查看器)以便在每次修改和运行脚本时刷新文件。这允许我将我的工作布局设置为干净:脚本有一个窗口,图形有一个窗口会自动刷新。

我想保持相同的布局,但使用 Matplotlib 图形(因为它们是交互式的)。我正在寻找一种使用方法,plt.show()始终与我第一次运行脚本时创建的图形相同

例如:

1.第一次运行

import matplotlib.pyplot as plt
import numpy as np 

fig, ax = plt.figure()    

noise = np.random.rand(1, 100)
ax(noise)
plt.show()
Run Code Online (Sandbox Code Playgroud)

2. 后续运行

import matplotlib.pyplot as plt
import numpy as np 

# This is the super command I am looking for
fig = plt.get_previous_run_figure()
ax = fig.axes

noise = …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

7
推荐指数
1
解决办法
4985
查看次数

计算 GeoPandas 中两个 GeoDataFrame(点)之间的所有距离

这是一个非常简单的案例,但到目前为止我还没有找到任何简单的方法。这个想法是获得 a 中定义的所有点GeoDataFrame和 another 中定义的点之间的一组距离GeoDataFrame

import geopandas as gpd
import pandas as pd

# random coordinates
gdf_1 = gpd.GeoDataFrame(geometry=gpd.points_from_xy([0, 0, 0], [0, 90, 120]))
gdf_2 = gpd.GeoDataFrame(geometry=gpd.points_from_xy([0, 0], [0, -90]))
print(gdf_1)
print(gdf_2)

#  distances are calculated elementwise
print(gdf_1.distance(gdf_2))
Run Code Online (Sandbox Code Playgroud)

这会产生 ingdf_1gdf_2共享相同索引的点之间的元素距离(还有一个警告,因为两个 GeoSeries 没有相同的索引,这就是我的情况)。

                geometry
0    POINT (0.000 0.000)
1   POINT (0.000 90.000)
2  POINT (0.000 120.000)
                    geometry
0    POINT (0.00000 0.00000)
1  POINT (0.00000 -90.00000)
/home/seydoux/anaconda3/envs/chelyabinsk/lib/python3.8/site-packages/geopandas/base.py:39: UserWarning: The indices of the two GeoSeries …
Run Code Online (Sandbox Code Playgroud)

python pandas geographic-distance shapely geopandas

4
推荐指数
1
解决办法
1527
查看次数