本文整理汇总了Python中plotly.graph_objs.Annotation方法的典型用法代码示例。如果您正苦于以下问题:Python graph_objs.Annotation方法的具体用法?Python graph_objs.Annotation怎么用?Python graph_objs.Annotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.graph_objs
的用法示例。
在下文中一共展示了graph_objs.Annotation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_title
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import Annotation [as 别名]
def draw_title(self, **props):
"""Add a title to the current subplot in layout dictionary.
If there exists more than a single plot in the figure, titles revert
to 'page'-referenced annotations.
props.keys() -- [
'text', (actual content string, not the text obj)
'position', (an x, y pair, not an mpl Bbox)
'coordinates', ('data', 'axes', 'figure', 'display')
'text_type', ('title', 'xlabel', or 'ylabel')
'style', (style dict, see below)
'mplobj' (actual mpl text object)
]
props['style'].keys() -- [
'alpha', (opacity of text)
'fontsize', (size in points of text)
'color', (hex color)
'halign', (horizontal alignment, 'left', 'center', or 'right')
'valign', (vertical alignment, 'baseline', 'center', or 'top')
'rotation',
'zorder', (precedence of text when stacked with other objs)
]
"""
self.msg += " Attempting to draw a title\n"
if len(self.mpl_fig.axes) > 1:
self.msg += " More than one subplot, adding title as " \
"annotation\n"
x_px, y_px = props['mplobj'].get_transform().transform(props[
'position'])
x, y = mpltools.display_to_paper(x_px, y_px,
self.plotly_fig['layout'])
annotation = go.Annotation(
text=props['text'],
font=go.Font(
color=props['style']['color'],
size=props['style']['fontsize']
),
xref='paper',
yref='paper',
x=x,
y=y,
xanchor='center',
yanchor='bottom',
showarrow=False # no arrow for a title!
)
self.plotly_fig['layout']['annotations'] += annotation,
else:
self.msg += " Only one subplot found, adding as a " \
"plotly title\n"
self.plotly_fig['layout']['title'] = props['text']
titlefont = go.Font(
size=props['style']['fontsize'],
color=props['style']['color']
)
self.plotly_fig['layout']['titlefont'] = titlefont