Plot lineplot on top of seaborn heatmap using same axes

Viewed 1834

I have seaborn heatmap and I would like to plot a lineplot on top of it while using the same x and y axis that the heatmap is using.

I expected the line to behave like in this post and take up most of the space of the heatmap, but instead the output I got was the following plot where it only occupied a small section of the heatmap. How can I make the line take up most of the space in the heatmap?

Below is the minimal working example that produced the plot I linked above.

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

num = 11
a = np.eye(num)
x = np.round(np.linspace(0, 1, num=num), 1)
y = np.round(np.linspace(0, 1, num=num), 1)

df = pd.DataFrame(a, columns=x, index=y)

f, ax = plt.subplots()
ax = sns.heatmap(df, cbar=False)
ax.axes.invert_yaxis()
sns.lineplot(x=x, y=y)

plt.show()
1 Answers

Perhaps just a simple fix here:

sns.lineplot(x=x*num, y=y*num)

enter image description here

Related