python - 如何在X轴上添加水平滚动条?

标签 python plotly plotly-python

我想在X轴上添加一个(水平)滚动条,因为点数很大。我该怎么做?

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']添加范围 slider ,其功能超出了滚动条的功能:

plotly :

enter image description here

代码:

以下是在离线 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)

有关更多详细信息,请查看 here .

关于python - 如何在X轴上添加水平滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56108996/

相关文章:

python - 将 Django ORM 查询从多个数据库查找优化为可能的一个数据库查找

python - 在 plotly 中,如何创建链接的 X 轴?

python - 我想在plotly(python)中将数据显示为x轴上的百分比

plotly - 如何制作堆叠条形图并避免在 Plotly 中隐藏误差线

python - 无法使用 PyQt4 中的 QProcess 放弃新进程的权限

Python 正则表达式匹配带或不带逗号或小数的货币

python - Beautiful Soup 类型错误和正则表达式

python - 如何使用plotly中的 slider 更新y值(python)

Python 将瀑布图转换为 plotly

python - 阴谋冲刺 : How to integrate SHAP values