我想在图中创建额外的注释空间(请参阅附图中的绿色区域)。
目前,y 轴定义了绘图的高度。我可以将绘图推到超出 y.max 限制/在某个点(在图像中标记为红色)之后隐藏 y 轴吗?
我尝试避免轴到达“评论部分”(绿色)。
谢谢你!
在此输入图像描述 https://i.stack.imgur.com/RxlFV.png
我在回答你的另一个问题后偶然发现了这个问题,并认为它很有趣。
这就是你所追求的吗?
关键要素:
创建提升注释的关键要素是:
-
xref
and yref
被设置为'paper'
,因此使用图表的背景 for xy
坐标而不是图形数据值
- 使用 > 1.00 表示
y
定位
-
layout['margin']
top设置一个值以创建上边距,从而将图形区域向下推
示例代码:
它确实比看起来简单得多。
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})
Note:
您必须创建自己的图表标题(而不是依赖于title
参数可用在layout
),因为您需要自己定位图表标题。否则自动标题和注释将会重叠。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)