Skip to content

Wrong width of bar in bar plots #1776

Open
@bklingen

Description

@bklingen

I would have expected a single bar with a width of 0.05 here:

library(plotly)

plot_ly(
  type = 'bar',
  x = 0.2,
  y = 10,
  width = 0.05
) %>% 
layout(
  xaxis=list(range=c(0,1))
)

Instead, I get a single bar with width 0.6 (and not 0.05).

Similarily, I would have expected two bars, each of width 0.05 here:

plot_ly(
  type = 'bar',
  x = c(0.2, 0.5),
  y = c(10, 8),
  width = 0.05
) %>% 
layout(
  xaxis=list(range=c(0,1))
)

Instead, it shows two bars, but not of width 0.05.

Only if I'm plotting 4 bars (or more) do I get the correct width (of 0.05) for each:

plot_ly(
  type = 'bar',
  x = c(0.2, 0.5, 0.6, 0.7),
  y = c(10, 8, 7, 3),
  width = 0.05
) %>% 
layout(
  xaxis=list(range=c(0,1))
)

Checking with a Javascript codepen, using

var trace0 = {
  type: 'bar',
  x: [0.2],
  y: [10],
  width: 0.05
}

var layout = {
  xaxis: {range: [0, 1]}
}

var data = [trace0]

Plotly.newPlot('myDiv', data, layout);

does give the expected result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions