1
votes

I'm creating a notebook that lets users select series to graph in a plotly bar chart and scatter plot. The graphs are generating, but in certain cases, its hard to even tell that the graph contains any data.

Take this graph for example. It is a graph of 5000 entries, all of which have data between -4 and 4. I'm graphing the index column on the x axis and the values on the y axis. TLDR: Whenever the x axis range is large, the bars are too small to see.

enter image description here

So far, I've tried changing the default color of the graph to be red so that the bars at least stand out more. But as you can see in the picture, its still hardly visible.

I know that there are ways to start plotly zoomed in already, which might be a good solution. But because I'm not sure what the data will look like ahead of time (it could be numeric, dates, strings, etc.), I've struggled to create a good heuristics to make the zoomed in graph look good.

Does anyone have suggestions about how to configure the plotly zoom settings or otherwise make the chart more visible on initial render?

I used the following code to generate the graph:

import plotly.graph_objects as go
import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(5000, 1), columns=list('A'))

fig = go.Figure(data=[
    go.Bar( 
        y = df['A'],
        name = 'A'
    )]
)

fig.show()

Thanks a ton!!

1

1 Answers

0
votes

By default, all data is displayed, but it is possible to limit the x-axis data to be displayed. Here you specify the granularity of data you want to display as initial. You can also change the granularity by clicking on the zoom icon at the top, but it will be more convenient if you set it so that you can use the scroll function of the mouse to zoom.

import plotly.graph_objects as go
import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(5000, 1), columns=list('A'))

fig = go.Figure(data=[
    go.Bar( 
        y = df['A'],
        name = 'A'
    )]
)
fig.update_layout(xaxis=dict(range=[df.index[1750], df.index[2000]]))
config = dict({'scrollZoom': True})
fig.show(config=config)

enter image description here