如何使用Plotly创建垂直滚动条?

2024-06-16 08:56:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想为Plotly中的折线图创建一个垂直卷轴。为了直观起见,垂直卷轴如下图所示

enter image description here

假设我们有如下6个折线图,那么我们如何在画布上创建垂直滚动条呢

import plotly.graph_objects as go
import plotly.io as pio
from plotly.subplots import make_subplots
import pandas as pd

# data
pio.templates.default = "plotly_white"
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
df = df.set_index('Date')
df.tail()
cols = df.columns[:-4]
ncols = len(cols)

# subplot setup
fig = make_subplots(rows=ncols, cols=1, shared_xaxes=True)

for i, col in enumerate(cols, start=1):
    fig.add_trace(go.Scatter(x=df[col].index, y=df[col].values), row=i, col=1)

fig.show()

谢谢你给我的建议或好的阅读材料


Tags: csvimportgodfmakeasfigcol
1条回答
网友
1楼 · 发布于 2024-06-16 08:56:16

我用plotly dash制作了一个单页web应用程序。在这个仪表板中,我想创建一个侧面也有一个sroller的垂直条形图。 我导入了以下依赖项:

from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash
import dash_table
import plotly.graph_objs as go
import pandas as pd

在app.layout中,我在包含dcc.graph组件的html.Div中给出了css样式参数:-

dcc.Graph(
            id='doctors',
            figure={}
        ),style={"maxHeight": "400px", "overflow": "scroll"})
        ], width={'size': 6})

后来在@app回调中,我给出了垂直条形图的高度:-

fig.update_layout(height = (30*len(all_by_doctor)), title_text='Total bookings 
by {} doctors'.format(len(all_by_doctor)),plot_bgcolor='#ffffff')

相关问题 更多 >