如何在条形图中设置 x 和 y 范围。我的 plotly 目前喜欢以下内容(在 python 中):
x = [1,2,3,5,6,7]
y = [3,5,76,8,96,1]
data = [go.Bar(
x=x,
y=y
)]
layout = {
'xaxis': {'title': 'Query Duration'},
'yaxis': {'title': 'Proportion (%)'},
'barmode': 'relative'
}
但正如我测试的那样,我无法将 range 发送到 data 或 layout。
请您参考如下方法:
您可以像这样定义布局。 xaxis 或 yaxis 的 range 属性可用于此目的。
range (array)
Sets the range of this axis. If the axis type is "log", then you must take the log of your desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2). If the axis type is "date", it should be date strings, like date data, though Date objects and unix milliseconds will be accepted and converted to strings. If the axis type is "category", it should be numbers, using the scale where each category is assigned a serial number from zero in the order it appears. Each object has one or more of the keys listed below.
检查 official documentation还有。
x = [1,2,3,5,6,7]
y = [3,5,76,8,96,1]
data = [go.Bar(
x=x,
y=y
)]
layout = {
'xaxis': {'title': 'Query Duration', 'range': [1, 10]},
'yaxis': {'title': 'Proportion (%)'}, 'range': [1, 100]},
'barmode': 'relative'
}
