python matplotlib 绘制双Y轴曲线图
2017-07-06 15:57
531 查看
要点就是ax2 = ax1.twinx(), 制作一个兄弟轴。代码如下:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
绘制结果:
import matplotlib.pyplot as plt import numpy as np x = np.arange(0., np.e, 0.01) y1 = np.exp(-x) y2 = np.log(x) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.plot(x, y1) ax1.set_ylabel('Y values for exp(-x)') ax1.set_title("Double Y axis") ax2 = ax1.twinx() # this is the important function ax2.plot(x, y2, 'r') ax2.set_xlim([0, np.e]) ax2.set_ylabel('Y values for ln(x)') ax2.set_xlabel('Same X for both exp(-x) and ln(x)') plt.show()1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
绘制结果:
相关文章推荐
- python matplotlib 绘制双Y轴曲线图
- Python使用matplotlib绘制正弦和余弦曲线的方法示例
- Python使用matplotlib绘制三维曲线
- pyqt中使用matplotlib绘制动态曲线 – pythonic
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- python 使用numpy matplotlib绘制图表
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- python中matplotlib绘制图形
- Python:使用matplotlib绘制图表
- Python:使用matplotlib绘制图表
- 【转载】Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- 用Python的Matplotlib绘制LaTeX用的论文插图替代Matlab等收费软件终将成为时尚
- Python使用matplotlib绘制动画的方法
- Python图表绘制:matplotlib绘图库入门