1
$\begingroup$

I have two dataframes (both of different lengths, etc) but they have exact same columns and I would like to explore the distribution of one of these columns by plotting a boxplot.

However, how do I get it on the same axis? And how can I set the y-axis for this? The below code puts the boxplots side by side in separate graphs but I would like them to have the same axis so I can compare them easier.

f, axes = plt.subplots(1, 2)
sns.boxplot( x="status",y="assets" ,data=df1, palette="Set3",ax=axes[0])
sns.boxplot( x="status",y="assets" ,data=df2, palette="Set3",ax=axes[1])
fig.tight_layout()
plt.show()
$\endgroup$
1
$\begingroup$

So the problem is how to visualise your box plots so that they appear in the same plot (axes).

To do this, it is simply a minor alteration to your code.

f, axes = plt.subplots(1, 2)
sns.boxplot(x="status",y="assets" ,data=df1, palette="Set3",ax=axes[0])
sns.boxplot(x="status",y="assets" ,data=df2, palette="Set3",ax=axes[0])
fig.tight_layout()
plt.show()

The alteration is on the data=df2 line.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.