plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

_bullet measure and range bars have issues if the data set has negative values

Open ksheehy opened this issue 1 year ago • 3 comments
trafficstars

The issue is with the method of sorting the data from highest to lowest. The data needs to be sorted so both, the largest positive and negative values are plotted first.

# Vertical Velocity
data = (
  {"label": "Vertical Velocity", "sublabel": "[FPM]",
  "range": sorted([-5000, -3000, 3000, 5000]), "performance": [-2000, -1000, 1000, 2000], "point": [500], 'command': [600]},
)

fig = ff.create_bullet(
    data, titles='label', subtitles='sublabel', markers='point',
    measures='performance', ranges='range', orientation='v',
    title='Bullet Chart',
    scatter_options={'marker': {'symbol': 'diamond'}},
    width=300,
)

fig.show()

Here is the current implementation - you can see since the sort function puts the -5000 tick mark last and the bar on top of all less negative values. Screenshot 2024-01-26 130212

Here is a fix. Screenshot 2024-01-26 130307

I did a little search on this function and it looks like it is being depreciated. I appologize if I have butchered the PR process.

ksheehy avatar Jan 26 '24 12:01 ksheehy

Thank you for reporting this, @ksheehy

Coding-with-Adam avatar Feb 01 '24 14:02 Coding-with-Adam

Hi @archmoj Here's the code pen for this issue: https://codepen.io/charming-data/pen/ExJwxRY

Coding-with-Adam avatar Mar 28 '24 16:03 Coding-with-Adam

Thanks very much for the PR. This looks good. Please add a test in packages/python/plotly/plotly/tests/test_optional/test_figure_factory/test_figure_factory.py to lock this bug.

archmoj avatar Mar 28 '24 16:03 archmoj