plotly / plotly/plotly.py

Bar chart with timeseries index not displaying depending on proximity of the times

Open
#2,987 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Found an issue causing a bar chart to display nothing when displaying timeseries data. It seems to be caused by having stacked data at two points which are very close in time (e.g. 12:00:00 and 12:00:01) and then one point much further away (e.g. 17:00:00).

import pandas as pd
import plotly.express as px

times = ['2020-12-18 02:15:00', '2020-12-18 02:15:00', '2020-12-18 02:15:00', '2020-12-18 02:15:01']  
#times = ['2020-12-18 02:15:00', '2020-12-18 02:15:00', '2020-12-18 02:15:00', '2020-12-18 02:15:00'] <-- works
vals = [10, 50, 20, 350, 250]

# Uncomment to cause bar chart to display no data
# times.append('2020-12-18 13:00:00')
# vals.append(1)
  
df = pd.DataFrame(list(zip(times, vals)), 
               columns =['DT', 'Val']) 

df['DT'] = pd.to_datetime(df['DT'])

df = df.set_index('DT')
fig = px.bar(df, x=df.index, y=df['Val'])

fig.show()
  • The code unchanged displays the figure fine
    1
  • If you uncomment the two append lines, adding in a data point which is further away, then the figure is empty
    2
  • If you uncomment the two append lines and changes the initial times list so that they are all :00, the figure displays fine
    3

Therefore it seems to be caused by having points at 02:15:00 / 02:15:01 and then a point much later at 13:00:00

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the issue's pandas and Plotly Express reproduction, first with the close timestamps and then with the additional 13:00:00 point. Compare the generated figure data or rendering in both cases; done means the bar chart displays the supplied timeseries data in the failing case without breaking the working examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, plotly, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.