使用打印文本仅绘制符合特定标准的数据

2024-06-16 10:12:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我运行一个脚本,从html代码行中检索数据。然后我把这些数据绘制在地图上。现在,我使用下面的脚本来绘制我在地图上检索到的所有数字,其中c.high0是我从html脚本中提取的数字。你知道吗

for c in cities :
    c.retrieveTemps()
    long, lat = c.long, c.lat
    x, y = map(float(long), float(lat))
    plt.text(x, y, c.high0, fontsize=7, fontweight='bold')

这就像它应该的那样工作,但是,我只想在它们大于等于34时绘制数字。有没有办法做到这一点,也许是在打印文本线路?我被难住了。谢谢!你知道吗


Tags: 数据代码in脚本forhtml地图绘制
1条回答
网友
1楼 · 发布于 2024-06-16 10:12:39

关于:

for c in cities :
    c.retrieveTemps()
    long, lat = c.long, c.lat
    x, y = map(float(long), float(lat))
    if c.high0 >= 34:
        plt.text(x, y, c.high0, fontsize=7, fontweight='bold')

如果您真的需要在plt线内进行:

plt.text(x, y, c.high0 if c.high0 >= 34 else '', fontsize=7, fontweight='bold')

相关问题 更多 >