Skip to content
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

Bar plot shows too many ticks #2421

Open
emrichter opened this issue Feb 3, 2025 · 1 comment
Open

Bar plot shows too many ticks #2421

emrichter opened this issue Feb 3, 2025 · 1 comment

Comments

@emrichter
Copy link

In plotly 4.10.4 a bar plot with only one date observation shows actually multiple ticks when the ticks' format is converted. Here a minimal reproducible example:

library(dplyr)
library(plotly)

df <- tibble(Time = "2025-01", Animal = "Monkey", value = 2)

df %>%
  plot_ly(x = ~Time, y= ~value, color = ~Animal) %>%
  layout(
    xaxis = list(
      type = "date",
      tickformat = "%b '%y"
    )
  )

Image

This is not the case though for a stacked bar plot:

df <- tibble(Time = c("2025-01", "2025-01"), Animal = c("Monkey", "Lion"), value = c(2, 3))

df %>%
  plot_ly(x = ~Time, y= ~value, color = ~Animal) %>%
  layout(
    barmode = "stacked",
    xaxis = list(
      type = "date",
      tickformat = "%b '%y"
    )
  )

Image

When looking at the dates without formatting one can see a few minimal shifts around the actual date:

df <- tibble(Time = "2025-01", Animal = "Monkey", value = 2)

df %>%
  plot_ly(x = ~Time, y= ~value, color = ~Animal) %>%
  layout(
    xaxis = list(
      type = "date"
    )
  )

Image

Is this already somewhere addressed?

@romanzenka
Copy link

I am not aware of this being a duplicate. As a workaround, you can switch the X axis type from date to just text and it will work, but it is definitely not ideal. I think this is a strange corner case that needs to be fixed either in the plotly.js or plotly.R, not sure which one just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants