Notes
- 用
plt.subplots
在一幅大 figure 里画几幅小图; - 一幅小图里可能画多条曲线;
plot
画连续曲线或散点,指定线型、颜色;scatter
散点图;bar
柱状图,设定纵轴坐标上、下限,打数值标签;
Rendering
![plt.subplots](https://i-blog.csdnimg.cn/blog_migrate/9fe8e6db65b8ebd57051e30fe871a5b9.png)
Code
import matplotlib.pyplot as plt
import numpy as np
from scipy.special import expit
fig, ax = plt.subplots(2, 2)
t = np.arange(0.0, 2.0, 0.1)
data_1 = np.sin(t * np.pi)
data_2 = np.cos(t * np.pi)
ax[0][0].plot(t, data_1, 'r*')
ax[0][0].plot(t, data_2, 'b-')
data_3 = -7 * t - 2
ax[0][1].scatter(t, data_3)
name_4 = ['a', 'b', 'c', 'd']
data_4 = [0.71, 0.83, 0.94, 0.68]
ax[1][0].bar(name_4, data_4, width=0.35)
ax[1][0].set_ylim([0, 1])
for x, y in enumerate(data_4):
ax[1][0].text(x, y, y)
data_5 = expit(t * np.pi)
ax[1][1].plot(t, data_5, 'y*')
plt.show()
Reference
- Matplotlib的子图subplot的使用
- matplotlib subplot 子图
- Plotting categorical variables
- How to set xlim and ylim for a subplot in matplotlib [duplicate]
- Grouped bar chart with labels
- matplotlib可视化之如何给图形添加数据标签?
- matplotlib模块数据可视化-绘制柱状图
- Adding value labels on a matplotlib bar chart