【问题标题】:Plot lineplot on top of seaborn heatmap using same axes使用相同的轴在 seaborn 热图上绘制线图
【发布时间】:2020-10-12 09:54:37
【问题描述】:

我有 seaborn 热图,我想在它上面绘制一个线图,同时使用与热图相同的 x 和 y 轴。

我希望这条线的行为类似于this post 并占据热图的大部分空间,但我得到的输出是the following plot,它只占据了热图的一小部分。如何让线条占据热图中的大部分空间?

下面是生成我上面链接的情节的最小工作示例。

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()

【问题讨论】:

  • sns.lineplot(x=x*num, y=y*num)?
  • @BigBen 正是我想要的。如果你回答我的问题,我会接受它是正确的

标签: python python-3.x pandas matplotlib seaborn


【解决方案1】:

也许只是一个简单的修复:

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

【讨论】:

    猜你喜欢
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 1970-01-01
    • 2019-03-27
    • 2015-04-04
    • 2019-08-25
    • 2021-12-05
    相关资源
    最近更新 更多