python的matplotlib实现双Y轴
2016-09-21 16:48
676 查看
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,'r',label="right"); ax1.legend(loc=1) ax1.set_ylabel('Y values for exp(-x)'); ax2 = ax1.twinx() # this is the important function ax2.plot(x, y2, 'g',label = "left") ax2.legend(loc=2) 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()
结果为:
相关文章推荐
- Matlab的Python实现Scipy和Matplotlib简介
- Python量化分析—指数基金定投及Matplotlib作图: 实现双Y轴和中文显示
- python中Matplotlib实现绘制3D图的示例代码
- Python Matplotlib实现三维数据的散点图绘制
- Convolution卷积算法python以numpy,Matplotlib实现
- 在python3的matplotlib下实现不同颜色散点图
- Python+matplotlib+numpy实现在不同平面的二维条形图
- Python使用Matplotlib实现雨点图动画效果的方法
- Python+matplotlib实现计算两个信号的交叉谱密度实例
- python实现Kmeans文本聚类,通过PCA降维和Matplotlib显示聚类3d三维图像
- python3.3+numpy+matplotlib 实现绘图
- Python/Matplotlib实现雨点图动画
- python+matplotlib实现鼠标移动三角形高亮及索引显示
- Python使用matplotlib实现在坐标系中画一个矩形的方法
- Python实现在matplotlib中两个坐标轴之间画一条直线光标的方法
- 基于Python实现matplotlib中动态更新图片(交互式绘图)
- Python使用matplotlib和pandas实现的画图操作【经典示例】
- Python+matplotlib实现填充螺旋实例
- Python实现在tkinter中使用matplotlib绘制图形的方法示例
- python+matplotlib实现礼盒柱状图实例代码