Skip to content

inconsistency in (bar) chart api - width does not accept pandas series #1231

Closed

Description

@roeap

Hi Plotly Team,

I may have stumbled across an inconsistency in the api for the bar chart trace. I have gotten used to be able to pass pandas series to trace properties. However assigning the width of a bar chart does not work as expected if a pandas series is passed - the trace is not displayed. A simple example to reproduce the behavior in a Jupyter Notebook is provided below.

import pandas as pd
import plotly.graph_objs as go

df = pd.DataFrame({
    'Group': [1, 2, 3],
    'Height': [3, 2, 1],
    'Width': [0.1, 0.2, 0.3],
})

traces = [
    go.Bar(
        x=df['Group'],
        y=df['Height'],
        width=df['Width'].tolist(),
        xaxis='x',
    ),
    go.Bar(
        x=df['Group'],
        y=df['Height'],
        width=df['Width'],
        xaxis='x2',
    ),
]

layout = go.Layout(
    xaxis={'domain': [0, 0.48]},
    xaxis2={'domain': [0.52, 1]},
)

go.FigureWidget(
    data=traces,
    layout=layout,
)

While the workaround is quite simple, it might be worth considering to make it work with pandas series as well.

Thanks for this great library!

Activity

  1. jonmmease commented on Oct 20, 2018

    @jonmmease
    Contributor

    Thanks for the report @roeap, I see what you mean.

    Technical notes:
    This probably means that plotly.js is not properly handling a typed array passed as the bar.width property, but we should confirm this in a codepen and open a plotly.js issue if so.

  2. added
    bug
    on Oct 20, 2018
  3. bpostlethwaite commented on Oct 23, 2018

    @bpostlethwaite
    Member

    @Kully can you port this bug report to a JS Codepen and open an issue in plotly.js (and link back here)?

  4. Kully commented on Oct 23, 2018

    @Kully
    Contributor

    can you port this bug report to a JS Codepen and open an issue in plotly.js

    Here's the JS Issue. I was able to replicate:
    plotly/plotly.js#3142

  5. added this to the v3.4.0 milestone on Oct 30, 2018
  6. jonmmease commented on Oct 30, 2018

    @jonmmease
    Contributor

    Fixed in Plotly.js in plotly/plotly.js#3169 and released in Plotly.js 1.42.0. This will be included in plotly.py 3.4.0.

    Here is the output of the original example on master:
    newplot 65

    Thanks for taking the time to report this @roeap!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions