How to create a vertical scroll bar with Plotly?

2024/10/6 18:32:34

I would like to create a vertical scroll for a line chart in Plotly. For visualisation, the vertical scroll is something depicted in the figure below.

enter image description here

Assume, we have 6 line chart as below, then how can we create a vertical scroll bar on the canvas

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()

Thanks for any tips or good reading material.

Answer

I made a single page web app using plotly-dash. In this dashboard I wanted to create a vertical bar chart that also had a sroller on the side. I imported the following dependencies:

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

In the app.layout I gave the css style parameters in the html.Div that contained my dcc.graph component:-

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

Later in the @app callback I gave height to my vertical bar graph:-

fig.update_layout(height = (30*len(all_by_doctor)), title_text='Total bookings 
by {} doctors'.format(len(all_by_doctor)),plot_bgcolor='#ffffff')
https://en.xdnf.cn/q/70340.html

Related Q&A

Django 1.7 makemigrations renaming tables to None

I had to move a few models from one app to another, and I followed the instructions on this answer https://stackoverflow.com/a/26472482/188614. Basically I used the CreateModel migrations generated by …

TypeError on CORS for flask-restful

While trying the new CORS feature on flask-restful, I found out that the decorator can be only applied if the function returns a string. For example, modifying the Quickstart example:class HelloWorld(r…

struct.error: unpack requires a string argument of length 16

While processing a PDF file (2.pdf) with pdfminer (pdf2txt.py) I received the following error:pdf2txt.py 2.pdf Traceback (most recent call last):File "/usr/local/bin/pdf2txt.py", line 115, in…

SELECT EXISTS vs. LIMIT 1

I see SELECT EXISTS used a lot like:if db.query("""SELECT EXISTS (SELECT 1 FROM checkoutWHERE checkout_id = %s)""" % checkout_id).getresult()[0][0] == t:vs. what i prefer:…

How to access a specific start_url in a Scrapy CrawlSpider?

Im using Scrapy, in particular Scrapys CrawlSpider class to scrape web links which contain certain keywords. I have a pretty long start_urls list which gets its entries from a SQLite database which is …

Escaping search queries for Googles full text search service

This is a cross-post of https://groups.google.com/d/topic/google-appengine/97LY3Yfd_14/discussionIm working with the new full text search service in gae 1.6.6 and Im having trouble figuring out how to …

dificulty solving a code in O(logn)

I wrote a function that gets as an input a list of unique ints in order,(from small to big). Im supposed to find in the list an index that matches the value in the index. for example if L[2]==2 the out…

Scrapy. How to change spider settings after start crawling?

I cant change spider settings in parse method. But it is definitely must be a way. For example:class SomeSpider(BaseSpider):name = mySpiderallowed_domains = [example.com]start_urls = [http://example.co…

numpy ctypes dynamic module does not define init function error if not recompiled each time

sorry for yet an other question about dynamic module does not define init function. I did go through older questions but I didnt find one which adress my case specifically enought.I have a C++ library …

How do I save Excel Sheet as HTML in Python?

Im working with this library XlsxWriter.Ive opened a workbook and written some stuff in it (considering the official example) - import xlsxwriter# Create a workbook and add a worksheet. workbook = xlsx…