import numpy as np
from plotly.offline import iplot
# Create the dataset.
n = 360
x = np.arange(n)
y = [np.sin(i*(np.pi/180)) for i in range(n)]
# Plot the sin wave.
data = []
data.append({'x': x,
'y': y})
# Create the annotations.
notes = []
notes.append({'text': ('An annotation at the top of the graph.<br><br>'
'And some more rambling text to take up some '
'more space on the graph to represent<br>'
'a longer annotation, just because we can.<br><br>'
'And one more for good measure.'),
'x': 0.00,
'y': 1.60,
'xref': 'paper',
'yref': 'paper',
'showarrow': False,
'align': 'left'})
notes.append({'text': 'Elevated Graph Annotation Example',
'x': 0.00,
'y': 1.15,
'xref': 'paper',
'yref': 'paper',
'showarrow': False,
'font': {'size': 18}})
# Setup the layout.
layout = {}
layout['annotations'] = notes
layout['margin'] = {'t': 175}
# Plot the data. (May also use `plot` rather than `iplot`)
iplot({'data': data, 'layout': layout})
在回答了你的另一个问题后,我无意中发现了这个问题,觉得很有趣
这就是你想要的吗
关键要素:
创建提升注释的关键要素包括:
xref
和yref
被设置为'paper'
,因此使用图形的背景作为xy
坐标,而不是图形数据值y
定位layout['margin']
top设置一个值以创建上边距,从而向下推图形区域示例代码:
它确实比看起来简单得多
注:
您必须创建自己的图形标题(而不是依赖于
layout
中可用的title
参数),因为您需要自己定位图形标题。否则,自动标题和注释将重叠相关问题 更多 >
编程相关推荐