I have a heatmap and want to plot certain labeled points over the heatmap. The result should look something like this:
This figure is obtained with the following code:
import pandas as pdimport matplotlib.pyplot as pltimport seaborn as sns# Create DataFrame with the heatmap datadf = pd.DataFrame({'x': [1, 1, 2, 1, 2, 2],'y': [1, 2, 1, 3, 2, 3],'value': [9, 8, 1, 0, 6, 2]})# Sort the DataFrame for the heatmapdf = df.pivot(index='y', columns='x', values='value')# Plot the heatmapplt.figure()sns.heatmap(df, annot=False, cmap='viridis')# Create DataFrame with point datapoints = pd.DataFrame({'x': [1.3, 2.1],'y': [2.3, 1.0]})# Convert scatter points to heatmap grid coordinatespoints['x'] = points['x'] - 0.5 # ? automate 0.5 ?points['y'] = points['y'] - 0.5 # ? automate 0.5 ?# Plot the scatter dotssns.scatterplot(data=points, x='x', y='y')# Add scatter labelsfor i, row in points.iterrows(): plt.text(row['x']+0.04, row['y']+0.05, i+1) # ? automate location adjustments ?plt.show()
Now, my data looks very different, and I am generating several heatmaps which all have very different scales. What is a reliable way to obtain such heatmaps with points on them?