三个访问图轴问题

时间:2018-07-12 21:36:22

标签: python pandas yaxis

我试图创建一个具有三个y轴和单个x轴的图。我研究了各种示例,并在独立的脚本中实现了这些示例,但是无法使第三轴在我已经使用的脚本中工作。分配给3 y轴的数据(data [3]和data [4])未应用到第三轴

import numpy as np
import pandas as pd
from datetime import datetime as dt
import matplotlib.ticker as mticker
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

time_start = dt.strptime('2018-04-03 13:15:00', '%Y-%m-%d %H:%M:%S')
time_end = dt.strptime('2018-04-03 13:30:00', '%Y-%m-%d %H:%M:%S')

data = [pd.Series([100,500],[time_start,time_end]), 
        pd.Series([500,100],[time_start,time_end]), 
        pd.Series([300, 300],[time_start,time_end]),
        pd.Series([0,0.015],[time_start,time_end]), 
        pd.Series([0.007, 0.007],[time_start,time_end])]

color1 = "#e5f5e0"
color2 = '#2ca25f'
color3 = 'k'
color4 = "#a51a3f"
color5 = "#c68d9c"
color_gridline = '#A6A5A5'

fig= plt.figure(figsize=(11,8.5))
ax_l1 = fig.add_subplot(111)
ax_l2 = ax_l1.twinx()
ax_r = ax_l1.twinx()

with pd.plot_params.use('x_compat', True):
        ax_l2.spines['right'].set_position(('axes', 1.1))
        ax_l2.spines['right'].set_color('red')
        ax_l1.spines['right'].set_color('blue')
        ax_r.spines['left'].set_color('green')
        ax_l2.tick_params(direction='out', pad=15)
        ax_l2 = fig.add_subplot(111)
        data[0].dropna().plot(ax=ax_l1, style=color1, label=labels['y1_raw']+', 20 Hz', linewidth=1, zorder=3)
        data[1].dropna().plot(ax=ax_l1, style=color2, label=labels['y1_avg'], linewidth=1, zorder=4)
        data[2].dropna().plot(ax=ax_r, style=color3, label=labels['y2'], marker='o', markersize=3, linewidth=1, zorder=2)
        data[3].dropna().plot(ax=ax_l2, style=color4, label=labels['y3_raw']+', 20 Hz', linewidth=1, zorder=5)
        data[4].dropna().plot(ax=ax_l2, style=color5, label=labels['y3_avg'], linewidth=1, zorder=6)

0 个答案:

没有答案