2.绘制折线图

#  2.1.1 使用plot()绘制折线图

import numpy as np
import matplotlib.pyplot as plt
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
plt.plot(arr[0], arr[1:])

运行如下

## 2.1.2实例1:未来15天最高气温和最低气温

# 01_maximum_minimum_temperatures
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4, 19)
y_max = np.array([34, 35, 30, 33, 29, 30, 30, 28, 32, 29, 26, 27, 28, 25, 31])
y_min = np.array([17, 15, 18, 20, 21, 20, 19, 18, 17, 18, 17, 18, 19, 17, 17])
# 绘制折线图
plt.plot(x, y_max)
plt.plot(x, y_min)
plt.show()

运行如下

# 2.2 绘制柱形图或堆积柱形图

## 2.2.1 使用bar()绘制柱形图或堆积柱形图

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(5)
y1 = np.array([9, 7, 9, 9, 11])
# 柱形的宽度
bar_width = 0.3
# 绘制柱形图
plt.bar(x, y1, tick_label=['a', 'b', 'c', 'd', 'e'], width=bar_width)
plt.show()

运行如下

x = np.arange(5)
y1 = np.array([9, 7, 9, 9, 11])
y2 = np.array([8, 9, 8, 10, 12])
# 柱形的宽度
bar_width = 0.3
# 根据多组数据绘制柱形图
plt.bar(x, y1, tick_label=['a', 'b', 'c', 'd', 'e'], width=bar_width)
plt.bar(x + bar_width, y2, width=bar_width)
plt.show()

 运行如下 

# 绘制堆积柱形图
plt.bar(x, y1, tick_label=['a', 'b', 'c', 'd', 'e'], width=bar_width)
plt.bar(x, y2, bottom=y1, width=bar_width)
plt.show()

 运行如下

# 偏差数据
error = [2, 1, 2.5, 2, 1.5]
# 绘制带有误差棒的柱形图
plt.bar(x, y1, tick_label=['a', 'b', 'c', 'd', 'e'], width=bar_width)
plt.bar(x, y1, bottom=y1, width=bar_width, yerr=error)
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值