美文网首页TensorFlow@IT·互联网程序员
matplotlib的基本用法(十五)——主次坐标轴

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

作者: SnailTyan | 来源:发表于2017-05-05 19:23 被阅读49次

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

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

  • Demo
import numpy as np
import matplotlib.pyplot as plt

# 定义数据
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x ** 2
y2 = -1 * y1

# 定义figure
fig, ax1 = plt.subplots()
# 得到ax1的对称轴ax2
ax2 = ax1.twinx()
# 绘制图像
ax1.plot(x, y1, 'g-')
ax2.plot(x, y2, 'b--')

# 设置label
ax1.set_xlabel('X data')
ax1.set_xlabel('Y1', color = 'g')
ax2.set_xlabel('Y2', color = 'b')

plt.show()
  • 结果
图像

相关文章

网友评论

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

    本文链接:https://www.haomeiwen.com/subject/bqpstxtx.html