有没有一种方法可以在单个matplotlib图中使用hlines()函数绘制多条水平线?

问题描述 投票:0回答:1

我有一个pm2_5数据帧数据,我已经使用matplotlib散点图进行了绘制。我想在不同的[[y-values处插入多条水平线,我通过为每个[[y的每个不同值手动调用'''ax.axhline'''函数来完成此操作无论如何,有没有使整个过程自动化的方法?

# making a graph with delineated health levels of pm2.5 in the year 2015 fig, ax=plt.subplots(figsize=(10,7)); pm2_5.plot(kind='scatter',x='S_no',y='pm2_5',c='pm2_5',ax=ax, cmap='tab20b'); ax.axhline(y=150,linestyle ='--') ax.axhline(y=100,linestyle ='--') ax.axhline(y=200,linestyle ='--') ax.axhline(y=300,linestyle ='--') enter image description here
matplotlib graph customization scatter-plot horizontal-line
1个回答
0
投票
[ax.axhiline(y=i, linestyle='--') for i in [150,100,200,300]]
© www.soinside.com 2019 - 2024. All rights reserved.