H all,
I'd like to create a scatterplot with a title, subtitle, colours corresponding to a specific variable and size corresponding to another variable. I want to display the colour legend but not the size. Here is what I have so far:
# imports
import seaborn as sns
import matplotlib
from matplotlib import style
import matplotlib.pyplot as plt
# parameters
matplotlib.rcParams['font.family'] = "roboto"
style.use('fivethirtyeight')
# load data
iris = sns.load_dataset('iris')
# plot
ax = sns.relplot(
'sepal_length',
'sepal_width',
hue='species',
size='petal_width',
alpha=0.75,
kind="scatter",
legend=False,
data=iris
)
# make adjustments
ax.set_axis_labels(x_var='Sepal Length', y_var='Sepal Width')
plt.text(x=4.7, y=4.7, s='Sepal Length vs Width', fontsize=16, weight='bold')
plt.text(x=4.7, y=4.6, s='The size of each point corresponds to sepal width', fontsize=8, alpha=0.75)
plt.show()
Output:
Here are my questions:
1) Is there a better way to set a subtitle? I tried this using ax.suptitle("blah", y=1.05)
but it ends up sitting outside the scope of the figure. I don't like that I have to set x and y coordinates for my title/subtitle.
2) Is there a way for me to display the colour legend without showing the size legend? I would also like to be able to display this legend below the plot (or outside it). if you can answer that question, I'll change the title of this post, mark your answer as complete and create another question about the titles and subtitles
Many thanks!