python matplotlib实现双Y轴的实例
2019-03-28 10:58
399 查看
如下所示:
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()
结果为:
以上这篇python matplotlib实现双Y轴的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- python+matplotlib实现礼盒柱状图实例代码
- Python+matplotlib实现填充螺旋实例
- python+matplotlib实现动态绘制图片实例代码(交互式绘图)
- Python数据可视化教程之Matplotlib实现各种图表实例
- Python+matplotlib实现计算两个信号的交叉谱密度实例
- 对python中Matplotlib的坐标轴的坐标区间的设定实例讲解
- python+matplotlib绘制3D条形图实例代码
- Python Matplotlib实现三维/四维数据的柱状图绘制
- python—matplotlib数据可视化实例注解系列-----设置标注字体样式(matplotlib颜色库)
- python3.3+numpy+matplotlib 实现绘图
- Python实现的多项式拟合功能示例【基于matplotlib】
- python中Matplotlib实现绘制3D图的示例代码
- Python使用matplotlib和pandas实现的画图操作【经典示例】
- Convolution卷积算法python以numpy,Matplotlib实现
- python+matplotlib绘制饼图散点图实例代码
- python—matplotlib数据可视化实例注解系列-----之plot图线型设置
- Python+matplotlib实现华丽的文本框演示代码
- python+matplotlib绘制旋转椭圆实例代码
- Python实现在matplotlib中两个坐标轴之间画一条直线光标的方法
- Python+matplotlib+numpy实现在不同平面的二维条形图