TensorFlow@IT·互联网程序员

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

2017-05-05  本文已影响49人  SnailTyan

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

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

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()
图像
上一篇 下一篇

猜你喜欢

热点阅读