Python 使用plt.text仅打印满足特定条件的数据
我运行一个脚本,从html代码行中检索数据。然后我将这些数据绘制在地图上。现在,我使用下面的脚本绘制我在地图上检索到的所有数字,其中c.high0是我从html脚本中提取的数字Python 使用plt.text仅打印满足特定条件的数据,python,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=
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的数字。在plt.text行中是否有这样做的方法?我被难住了。谢谢 那么:
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')
哦,我以为c.high0是一个数字而不是一个字符串!不管怎样,我很高兴听到它起作用了。