我有以下代码可创建热图:
import matplotlib.pyplot as plt
import seaborn as sns
# Load dataset from seaborn
flights = sns.load_dataset('flights')
flights = flights.pivot('month', 'year', 'passengers')
# Plot heatmap
fig1, ax1 = plt.subplots(figsize=(8,8))
ax = sns.heatmap(flights, annot=True, fmt='d', cbar_kws={'label': 'Passenger Numbers'})
# Rotate x-axis labels
ax1.set_xticklabels(ax1.get_xticklabels(), rotation=45)
# Set font size for colorbar title
ax1.figure.axes[-1].yaxis.label.set_size(12)
# Set font size for colorbar labels
ax1.figure.axes[-1].tick_params(labelsize=10)
# Set font for x-axis labels
plt.xticks(fontsize=12, fontstyle='oblique')
# Set font for y-axis labels
plt.yticks(fontsize=12, fontstyle='oblique')
# Set title
plt.title('Heatmap Title', fontsize=39, weight='bold') # What needs to change here?
# Bold 'February' in y-axis
for label in ax.get_yticklabels():
if label.get_text() == 'February':
label.set_weight('bold')
plt.show()
如何移动标题,使其位于热图的底部?我尝试通过使用y=-0.01
来遵循此other post,但似乎不起作用吗?