matplotlib的基本用法(十五)——主次坐标轴

来源:互联网 发布:21端口是tcp 编辑:程序博客网 时间:2024/05/24 05:26

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

本文主要介绍matplotlib的一些用法。

  • Demo
import numpy as npimport matplotlib.pyplot as plt# 定义数据x = np.arange(0, 10, 0.1)y1 = 0.05 * x ** 2y2 = -1 * y1# 定义figurefig, ax1 = plt.subplots()# 得到ax1的对称轴ax2ax2 = ax1.twinx()# 绘制图像ax1.plot(x, y1, 'g-')ax2.plot(x, y2, 'b--')# 设置labelax1.set_xlabel('X data')ax1.set_xlabel('Y1', color = 'g')ax2.set_xlabel('Y2', color = 'b')plt.show()
  • 结果

图像

0 0