如何使x轴标签显示在带注释的热图python的底部而不是顶部?
问题描述:
我在python中创建了一个带注释的热图.问题在于x轴的默认位置在图形的顶部而不是底部.我一直在搜索参考页面,但无法弄清楚如何配置它.常规热图的默认值位于底部,而带注释的热图版本的默认值位于顶部.
I created a annotated heatmap in plotly python. The problem is that the default location for the x axis is at the top not the bottom of the graph. I have been searching the reference page and cannot figure out how to configure this. The default for a regular heatmap is at the bottom but the annotated heatmap version default is at the top.
答
Plotly的figurefactory
返回一个您可以修改的dict
ionary.在这种情况下,您可以将xaxis
的 side
设置为bottom
.
Plotly's figurefactory
returns a dict
ionary which you can modify. In this case you would set side
of your xaxis
to bottom
.
fig['layout']['xaxis']['side'] = 'bottom'
示例摘自此处.
import plotly.figure_factory as ff
import plotly
plotly.offline.init_notebook_mode()
z = [[.1, .3, .5],
[1.0, .8, .6],
[.6, .4, .2]]
x = ['Team A', 'Team B', 'Team C']
y = ['Game Three', 'Game Two', 'Game One']
z_text = [['Win', 'Lose', 'Win'],
['Lose', 'Lose', 'Win'],
['Win', 'Win', 'Lose']]
fig = plotly.figure_factory.create_annotated_heatmap(z,
x=x,
y=y,
annotation_text=z_text,
colorscale='Viridis')
fig['layout']['xaxis']['side'] = 'bottom'
plotly.offline.iplot(fig)