Adjust y-axis in Seaborn multiplot

前端 未结 1 899
情歌与酒
情歌与酒 2021-01-28 18:32

I\'m plotting a CSV file from my simulation results. The plot has three graphs in the same figure fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(24, 6)).

相关标签:
1条回答
  • 2021-01-28 18:37

    Based on the way you've written your code, you can refer to each subplot axis with g.axis and use g.axis.set_ylim(low,high). (A difference compared to the linked answer is that your graphs are not being plotted on a seaborn FacetGrid.)

    An example using dummy data and different axis ranges to illustrate:

    df = pd.DataFrame(np.random.uniform(0,10,(100,2)), columns=['a','b'])
    
    fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(8,4))
    
    
    g = sns.lineplot(x='a',
                     y='b',
                     data=df.sample(10),
                     ax=axes[0])
    g.axes.set_ylim(0,25)
    
    g = sns.scatterplot(x='a',
                        y='b',
                        data=df.sample(10),
                        ax=axes[1])
    g.axes.set_ylim(0,3.5)
    
    g = sns.scatterplot(x='a',
                        y='b',
                        data=df.sample(10),
                        ax=axes[2])
    g.axes.set_ylim(0,0.3)
    
    plt.tight_layout()
    plt.show()
    

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