Python 如何在plotly中更改注释方向?

Python 如何在plotly中更改注释方向?,python,plotly,data-visualization,plotly.js,Python,Plotly,Data Visualization,Plotly.js,假设我有下图: import numpy as np import plotly.graph_objs as go z=np.random.randint(1000, 11000, size=20) trace=dict(type='scatter', x=3+np.random.rand(20), y=-2+3*np.random.rand(20), mode='markers', marker=dict(col

假设我有下图:

import numpy as np
import plotly.graph_objs as go

z=np.random.randint(1000, 11000, size=20)
trace=dict(type='scatter',
          x=3+np.random.rand(20),
          y=-2+3*np.random.rand(20),
          mode='markers',
          marker=dict(color= z, 
                      colorscale='RdBu', size=14, colorbar=dict(thickness=20)))

axis_style=dict(zeroline=False, showline=True, mirror=True)
layout=dict(width=550, height=500,
            xaxis=axis_style,
            yaxis=axis_style,
            hovermode='closest',

           )
fig=go.FigureWidget(data=[trace], layout=layout)
fig

现在,假设我希望颜色栏有一个标题。由于plotly目前没有直接的方法来实现这一点,如果我理解正确,我将通过
注释来实现这一点,如图所示:

如我们所见,颜色栏标题出现:

fig=go.FigureWidget(data=[trace], layout=layout)
fig

但是,现在我想将颜色栏标题沿颜色栏横向放置,如下所示:

如何执行此操作?

请为您执行此操作。来自plotly文档。设置
textangle=-90
根据需要旋转注释

代码:

输出:

参数为您执行此操作。来自plotly文档。设置
textangle=-90
根据需要旋转注释

代码:

输出:

fig=go.FigureWidget(data=[trace], layout=layout)
fig
# import necessaries libraries
import numpy as np
import plotly.offline as py
import plotly.graph_objs as go

z = np.random.randint(1000, 11000, size=20)
# Create a trace
trace = dict(type='scatter',
             x=3+np.random.rand(20),
             y=-2+3*np.random.rand(20),
             mode='markers',
             marker=dict(color=z, colorscale='RdBu',
                         size=14, colorbar=dict(thickness=20)))
# Define axis_style
axis_style = dict(zeroline=False, showline=True, mirror=True)
# Specify layout style
layout = dict(width=550, height=500,
              xaxis=axis_style,
              yaxis=axis_style,
              hovermode='closest',
              )
# Update layout with annotation
layout.update(
    annotations=[dict(
          # Don't specify y position,because yanchor="middle" do it for you
          x=1.22,
          align="right",
          valign="top",
          text='Colorbar Title',
          showarrow=False,
          xref="paper",
          yref="paper",
          xanchor="right",
          yanchor="middle",
          # Parameter textangle allow you to rotate annotation how you want
          textangle=-90
        )
    ]
)
# Create FigureWidget
fig = go.FigureWidget(data=[trace], layout=layout)
# Plot fig
py.plot(fig)