python-3.x - Matplotlib 动画:如何擦除以前绘制的点?
问题描述
我正在获取和绘制纬度和经度。我可以在情节上对其进行动画处理,但我希望在绘制下一个点之前擦除先前绘制的点。另外我如何打破动画并转到其余代码(例如下面的 elif 语句)这是我的代码结构:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from matplotlib import animation
fig=plt.figure(figsize=(10,8))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()
ax.gridlines(draw_labels=True, color='black', linestyle='-', alpha=0.2)
def calc(i)
#Here the latitude.degrees and longitude.degrees are calculated (acquired)
plt.scatter(longitude.degrees, latitude.degrees, color='Red', marker='o')
while True:
if some condition:
anim = animation.FuncAnimation(fig, calc, interval=100, blit=False)
plt.show()
elif some other condition: # I never get to this statement. If i close plot, the entire Gui
#closes
some other code
window.close() # I am using pysimplegui
解决方案
如果您之前的轴元素,例如ax.plot(..,..)
存储在变量line
中。然后您可以按如下方式将其删除:
line = ax.plot(..,..)
for l in line:
l.remove()
del l
推荐阅读
- react-native - 修改 mapStateToProps 以实现通用访问
- apache-spark - Spark 按 Key 分组并对数据进行分区
- java - 从 JRE 7 或 8 升级到 JRE11 后,Java Swing JFrame 大小不同。如何使帧大小保持一致?
- asp.net-mvc - ASP.NET Core Razor Pages,有没有办法配置链接目录文件夹路径?
- perl - 从 tk perl 接口中的子例程传递变量
- r - 如何将日期放在 barplot() x 轴上?
- gitlab - GitLab-审稿人名单
- ruby-on-rails - puma 新的 fork-worker 选项,与 preload_app 的关系
- reactjs - 使用 React.useMemo 时不触发更新或无限循环
- json - 如何使用 XSLT 1.0 中的“替换”功能从我的 XML 中删除特殊字符以获得正确的 JSON 输出?