1.填充两条曲线之间区域
import matplotlib.pyplot as plt
import numpy as np
n = 1000
x = np.linspace(0, 8*np.pi, n)
sin_x = np.sin(x)
cos_x = np.cos(x/2)/2
plt.figure('filling graph')
plt.xlabel('x')
plt.ylabel('y')
plt.grid(linestyle=':')
plt.plot(x, sin_x, label='$y=sin(x)$')
plt.plot(x, cos_x, label='$y=cos(x)$')
plt.fill_between(x, sin_x, cos_x, sin_x < cos_x, color='orangered', alpha=0.5)
plt.fill_between(x, sin_x, cos_x, sin_x > cos_x, color='blue', alpha=0.5)
plt.legend()
# plt.tight_layout()
plt.show()
![](https://i-blog.csdnimg.cn/blog_migrate/875a95375ce1ea6030e07a7a6709f640.png)
2.柱状图
import matplotlib.pyplot as plt
import numpy as np
# 柱状图
plt.figure('bar chart')
plt.title('bar chart', fontsize=18)
apples = np.array([30, 25, 22, 36, 21, 29, 20, 24, 33, 19, 27, 15])
oranges = np.array([24, 33, 19, 27, 35, 20, 15, 27, 20, 32, 20, 22])
plt.xlabel('date', fontsize=14)
plt.ylabel('volume', fontsize=14)
x = np.arange(apples.size)
plt.bar(
x-0.2, apples, 0.4, label='apples'
)
plt.bar(
x+0.2, oranges, 0.4, label='apples'
)
plt.xticks(x, ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
plt.legend()
plt.show()