Issue
I have two reg plots in seaborn
sb.regplot(x="V", y="Matrix Time", data = df_1, scatter_kws={"color": "b"}, line_kws={"color": "red"})
sb.regplot(x="V", y="List Time", data = df_1, scatter_kws={"color": "g"}, line_kws={"color": "red"})
I want to display these plots side by side with the same scale on the Y-axis. I would really appreciate it if someone could help me with this.
Edit: I tried using
fig, ax = plt.subplots(1,2, figsize=(16,8))
sb.regplot(x="V", y="Matrix Time", data=df_1, ax=ax[0], scatter_kws={"color": "b"}, line_kws={"color": "red"})
sb.regplot(x="V", y="List Time", data=df_1, ax=ax[1], scatter_kws={"color": "g"}, line_kws={"color": "red"})
and while it did give me the 2 graphs side by side of the same size. The scale of the Y-axes for each graph were different.
https://i.stack.imgur.com/xkIUO.png
I was hoping to get both graph side by side such that the values on the Y axis of each graph are on the same horizontal level. Like this: https://i.stack.imgur.com/28iko.png
(I created the above image by taking a screenshot of each graph in powerpoint and adjusting the size such that the y axis values are at the same level)
Solution
In your code you need write:
sb.regplot(x="V", y="Matrix Time", data = df_1, scatter_kws={"color": "b"}, line_kws={"color": "red"}, ax=ax[0])
sb.regplot(x="V", y="List Time", data = df_1, scatter_kws={"color": "g"}, line_kws={"color": "red"}, ax=ax[1])
And for your edited Question, you need plt.subplots(..., sharey=True)
.
I write example:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
fig, ax =plt.subplots(1,2, sharey=True)
sns.regplot(x="total_bill", y="tip", data=tips, ax=ax[0])
sns.regplot(x="total_bill", y="tip", data=tips.loc[:10], ax=ax[1])
fig.show()
Output:
Answered By - user1740577
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.