Skip to content

Error bars on bar traces should adhere to 'tozero' findExtreme option #3029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
henrykeithturner opened this issue Sep 20, 2018 · 2 comments
Closed
Assignees
Labels
bug something broken

Comments

@henrykeithturner
Copy link

henrykeithturner commented Sep 20, 2018

Hi all,

I've been greatly enjoying using plotly but I've run into the following problem which I've been told may be a bug. When i have a couple of small bars on a bar chart, adding error bars (which do not extend to the negative region) causes a large whitespace between the xaxis and the xticks - as shown below with the accompanying script:

A = [10, 8, 12, 5, 8]
B = [0.5, 0.4, 10, 0.1, 0.4]
A_error = [1, 2, 1, 1, 2]
B_error = [0.2, 0.2, 2, 0.05, 0.2]
x_data = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']


trace1 = (py.graph_objs.Bar(x = x_data, y = A,
                            error_y = dict(type = 'data', array = A_error, visible = True), 
                            hoverinfo = 'x + y', name = 'A', opacity = 0.8, hoverlabel = dict(font = dict(size = 20))))    

trace2 = (py.graph_objs.Bar(x = x_data, y = B,
                            error_y = dict(type = 'data', array = B_error, visible = True), 
                            hoverinfo = 'x + y', name = 'B', opacity = 0.8, hoverlabel = dict(font = dict(size = 20))))   

data = [trace1, trace2]


layout = py.graph_objs.Layout(

    autosize = False,
    width = 1700,
    height = 1000,
    margin = dict(b = 100),
    showlegend = True,
    legend=dict(x=1, y=0.85, font = dict(size = 20), bgcolor = 'rgba(0,0,0,0)', bordercolor = 'black', borderwidth = 1),
    title = ('tick test'),
    titlefont = dict(size = 40),
        xaxis=dict(
            title  = 'x_variable',
        ticks = 'outside',
        tickwidth = 2, 
        titlefont = dict(
            size = 25),    
        tickfont=dict(
            size=15,
        ),
            tickangle = 270,
            automargin = True,
        ),

    yaxis=dict(
            title  = ('y_data'),
        ticks = 'outside',
        tickwidth = 2,
        titlefont = dict(
            size = 25),
        tickfont=dict(
            size=15,

        ),
            hoverformat = '.2f',
            automargin = True,


        ),    

)


fig = py.graph_objs.Figure(data=data, layout=layout)
py.offline.iplot(fig) 

plotly_tick_reproducible

The whitespace dissappears when I remove orange bars. There are more details in the link I first made below

https://community.plot.ly/t/large-white-space-between-xaxis-and-xticks/13739/3

Thanks,

Harry T

@etpinard
Copy link
Contributor

Hmm. This appears correct.

Error bar extreme values are computed with an opinionated padding corresponding the 5% of the axis length in px.

In your second trace, some error bar positions are close to zero (e.g. the at x=delta the error bar starts at y=0.05. So padding that y=0.05 extreme an extra 5% gets you an auto yaxis.range value in the negative. This negative starting range value is the "white space" you're referring to.

Now, I agree our default behavior isn't great for all situations. See issue #1876 for a list of planned auto-range-related improvements.

@alexcjohnson
Copy link
Collaborator

I think this can be considered a bug - as long as the negative sides of the errorbars don't reach past zero, we should give autorange a tight bound at 0. Likely this can be accomplished by having the errorbar calc inherit the tozero option bars pass to Axes.findExtremes:

var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: true});

which does exactly that: as long as the pre-padding lower bound is above zero (or the pre-padding upper bound is below zero) it adds a tight bound at zero, but the padding comes back as soon as you have explicit bounds on both sides of zero.

Note #3031 complicates this a bit... so the two should probably be tackled together.

@alexcjohnson alexcjohnson added the bug something broken label Sep 20, 2018
@etpinard etpinard changed the title xaxis to tick white space when adding error bars Error bars on bar traces should adhere to 'tozero' findExtreme option Sep 21, 2018
@etpinard etpinard self-assigned this Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

3 participants