I am trying to construct a seaborn plot with a subtitle and using matplotlib
's suptitle
function to do that. However, the two titles are off-center. They were off-center by default and when I tried manually correcting by setting horizontalalignment='center'
with both, nothing changed (which I sort of expected, since I'd read that those are the default values). I can try setting x and y values and trying to eyeball a center placement, but I want it to be exact. I've tried searching stack overflow and GitHub for responses to this issue but haven't found anything. How do I get both the title and the subtitle to center?
minimum viable example:
import seaborn as sns
import matplotlib
from matplotlib import pyplot as plt
import matplotlib.ticker as ticker
import seaborn as sns
%matplotlib inline
sns.set_theme(style="darkgrid")
X = [1,2,3]
y = [.5,.1,.9]
fig, ax = plt.subplots(figsize=(8, 5))
plt.rcParams['figure.dpi'] = 900
g = sns.scatterplot(x=X, y=y, color='#152238', alpha=0.9, legend = False)
# title
plt.suptitle('This is my Title', fontsize = 18,
horizontalalignment='center')
#set the title
plt.title('and this is a subtitle', fontsize = 14,
horizontalalignment='center')