Pandas squished plot on one axis

后端 未结 1 1355
独厮守ぢ
独厮守ぢ 2021-01-22 16:26

I have two data frames with i need to plot in one axis. Unfortunately one of displayed data and xticks are shifted to the left.

Test example:

impo         


        
1条回答
  •  隐瞒了意图╮
    2021-01-22 17:22

    I was only able to solve this by doing the plot in matplotlib directly:

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    
    df = pd.DataFrame()
    df['x'] = np.linspace(20, 30, 10)
    df['y'] = np.random.randint(1, 10, 10)
    
    df2 = pd.DataFrame()
    df2['x'] = np.linspace(1, 40, 50)
    df2['y'] = np.random.randint(1, 10, 50)
    
    fig, ax = plt.subplots()
    
    ax.bar(x=df.x, height=df.y)
    ax.plot(df2.set_index('x'), c='red')
    

    0 讨论(0)
提交回复
热议问题