matplotlib/seaborn 中 y 轴外部的框
我正在尝试在 matplotlib/seaborn 的热图上的 y 轴外部添加一个描述性框。我尝试了额外的子图和 hspan,但它们对我不起作用。请帮忙!
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
col1, col2 = np.random.rand(31), np.random.rand(31)
df = pd.DataFrame({'first': col1,
'second': col2}, index = range(70,101))
fig, ax = plt.subplots(1,figsize = (5,10))
sns.heatmap(data=df, annot=True, cmap='RdYlGn', cbar=False)
ax.invert_yaxis()
ax.tick_params('y', labelrotation=0)
I"m trying to add a descriptive box outside my y axis on my heatmap in matplotlib/seaborn. I tried an additional subplot and hspan, but they weren't working for me. Help please!
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
col1, col2 = np.random.rand(31), np.random.rand(31)
df = pd.DataFrame({'first': col1,
'second': col2}, index = range(70,101))
fig, ax = plt.subplots(1,figsize = (5,10))
sns.heatmap(data=df, annot=True, cmap='RdYlGn', cbar=False)
ax.invert_yaxis()
ax.tick_params('y', labelrotation=0)
Here is a picture of the box beside the y axis for reference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建两个子图,将热图放在右侧子图中,将文本放在左侧子图中。
You could create two subplots, put the heatmap in the right subplot and the text in the left one.