python matplotlib库中画横线
时间: 2023-08-26 13:13:14 浏览: 129
在Python的matplotlib库中,您可以使用`axhline`函数来画横线。这个函数可以在指定位置添加一条平行于x轴的横线。例如,您可以使用以下代码在图像中添加一条横线:
```python
import matplotlib.pyplot as plt
plt.plot(df_new['x'], df_new['产量'], linewidth=3, color='red')
plt.axhline(y=30, color='blue')
plt.show()
```
这段代码中,`plt.axhline(y=30, color='blue')`表示在y=30的位置画一条蓝色的横线。您可以根据需要自行调整y的值和线的颜色。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *3* [python 使用matplotlib.pyplot画线](https://blog.csdn.net/xy3233/article/details/122243820)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item]
- *2* [python使用matplotlib可视化线图(line plot)、在可视化图像中的指定位置添加横线(add horizontal line in...](https://blog.csdn.net/zhongkeyuanchongqing/article/details/122656204)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]