如何向X轴添加水平滚动条? [英] How to add a horizontal scrollbar to the X axis?
本文介绍了如何向X轴添加水平滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在X轴上加一个(水平)滚动条,因为点数很大.我该怎么做?
I want to add a (horizontal) scrollbar to the X axis, because the number of points is large. How can I do it?
trace0 = go.Scatter(
x = x1_values,
y = y1_values,
name = "V1"
)
data = [trace0]
layout = dict(title = title,
xaxis = dict(tickmode='linear', tickfont=dict(size=10)),
yaxis = dict(title = "Title")
)
fig = dict(data=data, layout=layout)
iplot(fig)
推荐答案
使用 plotly,您可以使用具有功能的 fig['layout']['xaxis']['rangeslider']
添加一个rangeslider超过滚动条:
Using plotly you can add a rangeslider using fig['layout']['xaxis']['rangeslider']
with functionality that exceeds that of a scrollbar:
剧情:
代码:
这是在离线 Jupyter Notebook 中使用一些随机数据的示例.
Here's an example using some random data in an off-line Jupyter Notebook.
# imports
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from IPython.core.display import display, HTML
import plotly.figure_factory as ff
import plotly.graph_objs as go
import pandas as pd
import numpy as np
# setup
display(HTML("<style>.container { width:35% !important; } .widget-select > select {background-color: gainsboro;}</style>"))
init_notebook_mode(connected=True)
np.random.seed(1)
# random time series sample
df = pd.Series(np.random.randn(1000),index=pd.date_range('1/1/2000', periods=1000)).cumsum().to_frame()+100
df.columns = ['Series1']
# trace / line
trace1 = go.Scatter(
x=df.index,
y=df['Series1'],
name = "AAPL High",
line = dict(color = 'blue'),
opacity = 0.4)
# plot layout
layout = dict(
title='Slider / Scrollbar',
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1m',
step='month',
stepmode='backward'),
dict(count=6,
label='6m',
step='month',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(
visible = True
),
type='date'
)
)
# plot figure
data = [trace1]
fig = dict(data=data, layout=layout)
iplot(fig)
有关详细信息,请查看此处.
For more details take a look here.
这篇关于如何向X轴添加水平滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文