假如现在有100条气温数据,把其中气温最高的前十条用条形图画出来,python代码实现
时间: 2024-02-11 16:09:39 浏览: 27
好的,以下是Python代码实现:
```python
import matplotlib.pyplot as plt
# 生成气温数据
temperatures = [30, 32, 33, 29, 35, 36, 37, 28, 31, 34, 26, 27, 38, 39, 40, 25, 41, 42, 43, 24, 23, 22, 44, 45, 46, 47, 21, 20, 19, 48, 49, 50, 18, 17, 16, 51, 52, 53, 54, 55, 56, 57, 58, 15, 14, 13, 12, 59, 60, 11, 10, 9, 61, 62, 63, 64, 8, 7, 6, 65, 66, 67, 68, 69, 70, 5, 4, 3, 71, 2, 72, 73, 74, 75, 76, 77, 1, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
# 找到气温最高的前十条
top_temperatures = sorted(temperatures, reverse=True)[:10]
# 生成条形图
plt.bar(range(len(top_temperatures)), top_temperatures)
# 设置x轴标签
plt.xticks(range(len(top_temperatures)), [f"Temperature {i+1}" for i in range(len(top_temperatures))])
# 设置标题和标签
plt.title("Top 10 Temperatures")
plt.xlabel("Temperature Rank")
plt.ylabel("Temperature (°C)")
# 显示图形
plt.show()
```
这段代码会生成一个条形图,其中显示出气温最高的前十条数据。你可以根据需要修改气温数据,生成不同的图形。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)