#!/bin/env python
# -*- coding: UTF-8 -*-

import matplotlib.pyplot as plt

# 设置一张图片中显示3条曲线,3个总坐标的例子
# 设置数据
x = range(3)
y_qps = [0, 1, 2, 3]
y_tps = [200, 100, 300, 200]
y_lag = [1, 0.5, 2.1, 2.0]

# 初始化画布
fig, ax = plt.subplots()
# 设置画布大小
fig.set_size_inches(10,6,forward=True)
# 初始化另外两个图层
ax2, ax3 = ax.twinx(), ax.twinx()
# 设置第三个坐标轴位置
rspine = ax3.spines['right']
rspine.set_position(('axes', 1.25))
ax3.set_frame_on(True)
ax3.patch.set_visible(False)
fig.subplots_adjust(right=0.75)

# 设置坐标轴标签
ax.set_ylabel("QPS")
ax2.set_ylabel("TPS")
ax3.set_ylabel("slave seconds behind")
# 设置坐标轴显示区间
ax.set_ylim(0, 500)
ax2.set_ylim(0, 5)

# 数据填充
ax.plot(x, y_qps, label="qps")
ax2.plot(x, y_tps, color='orange', linewidth=1.0, label="tps")
ax3.plot(x, y_lag, color='red', linewidth=1.0, label="slave seconds behind")

# 保存文件
plt.savefig("/tmp/ceshi.png")

测试代码执行结果如下:

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐