import pandas as pd
import seaborn as sns
# load data
df = sns.load_dataset('penguins', cache=False)
sns.scatterplot(data=df, x='bill_length_mm', y='bill_depth_mm', hue='sex')
plt.show()
sns.scatterplot(data=df, x='flipper_length_mm', y='body_mass_g', hue='sex')
plt.show()
When I draw two plots with seaborn, in one cell, in jupyter, I get this view:
I want to draw the plots, side by side, like this:
plot1 plot2
How I should do this?
Not two plots on one figure, but two plots on two separate figures.
fig, ax = plt.subplots(1,2)
sns.plotType(someData, ax=ax[0]) # plot1
sns.plotType(someData, ax=ax[1]) # plot2
fig.show()
%html
causes the figures to plot on top of each otheripython
, not Jupyter, or recommended creating subplots..plt.savefig('file.jpg')
to save each figure to a file.import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# load data
df = sns.load_dataset('penguins', cache=False)
# create and save figure
sns.scatterplot(data=df, x='bill_length_mm', y='bill_depth_mm', hue='sex')
plt.savefig('bill.jpg')
plt.close() # prevents figure from being displayed when code cell is executed
# create and save new figure
sns.scatterplot(data=df, x='flipper_length_mm', y='body_mass_g', hue='sex')
plt.savefig('flipper.jpg')
plt.close() # prevents figure from being displayed when code cell is executed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With