For resizing Seaborn figure-level plots, I've been following this convention:
fig, ax = plt.subplots(figsize=(10,5))
sns.catplot(x='xdata', y='ydata', data=df, kind='swarm', ax=ax)
This works for the catplot as well, however it generates a second, completely blank plot. Is this a bug in Seaborn (or am i doing something wrong)? Is there any way to properly resize this plot without getting a second blank plot (when i say blank plot i mean a plot with no data just same axis labels as the first plot)?
To set the size of markers, we can use the s parameter. This parameter can be used since seaborn is built on the matplotlib module. We can specify this argument in the scatterplot() function and set it to some value. Alternatively, we can control the size of the points based on some variables.
link code. Catplot can handle 8 different plots currently available in Seaborn. catplot function can do all these types of plots and one can specify the type of plot one needs with the kind parameter. So it is kind of one stop for every plot you will require for bivariate analysis. (
Consider not calling subplots
and use height and aspect arguments as this seaborn factorplot solution shows where aspect is the width multiple of height, likely to keep dimensions consistent:
sns.catplot(x='xdata', y='ydata', data=df, kind='swarm', height=5, aspect=2)
From help(sns.catplot)
output:
height : scalar, optional
Height (in inches) of each facet. See also: ``aspect``.
aspect : scalar, optional
Aspect ratio of each facet, so that ``aspect * height`` gives the width
of each facet in inches.
To demonstrate with random data:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
np.random.sample(71318)
df = pd.DataFrame({'xdata': np.random.choice(['pandas', 'r', 'julia', 'sas', 'spss', 'stata'], 100),
'ydata': np.random.choice(range(1,6), 100)})
sns.catplot(x='xdata', y='ydata', data=df, kind='swarm', height=5, aspect=2)
plt.show()
plt.clf()
plt.close()
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