# Time series xaxis range bigger than data domain

**URL:** https://community.plotly.com/t/time-series-xaxis-range-bigger-than-data-domain/3889
**Category:** Plotly R
**Created:** [April 10, 2017, 3:14pm UTC](https://community.plotly.com/t/time-series-xaxis-range-bigger-than-data-domain/3889 "2017-04-10T15:14:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Roger](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Roger](https://community.plotly.com/u/Roger)
#### Post date: [April 10, 2017, 3:14pm UTC](https://community.plotly.com/t/time-series-xaxis-range-bigger-than-data-domain/3889/1 "2017-04-10T15:14:06Z")

</div>

Hello,  
First of all I’d like to congratulate you on this amazing library.

I have been using Plotly to build a data monitoring program (time series). I have an issue regarding the xaxis range because, even though I define the range within a fixed set of values, the plotted axis’ range is always bigger, which makes sense in being able to clearly see all the markers. In the context of my application I would like that extra white space to be removed (see red arrows in picture below). I’ve searched in the forums for similar issues and I haven’t found anything helpful.

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/c/c2005fdc622a51ca2a5c43241c1fb86486f442a8.png)

Since I have data within a variable time frame, I would like the xaxis limits to be coincidental with the first (earliest) and last (latest) points of my data set.

I am aware that setting xaxis range will automatically zoom the graphic and rangeslider to the desired time frame but eventually this will be problematic when I add a rangeselector, since the “all” selector will zoom out of the desired time frame. Double-clicking the plot will also cause the plot to zoom out of the desired time window.

This is the code I am using to obtain the plot (removed the shapes and annotations for simplicity):

```
# Thresholds
alert = 6
critical = 8
min_value = 0
max_value = 10

# Time series
time_end <- Sys.time()
time_begin <- as.Date("2010-1-1 00:00:00")

x <- seq(time_begin, as.Date(time_end), "week")
y <- runif(n = length(x), min = 0, max = 10)

new_plot <- plot_ly(x = ~x, y = ~y)

new_plot<- layout(new_plot,
    titlefont = list(
      color = "rgba(0,0,144,1)",
      size = 16
    ),
    
    xaxis = list(
      title = "",
      rangeslider = list(type = "date"),
      range = c(as.numeric(as.Date(time_begin))*24*60*60*1000, 
                as.numeric(as.Date(time_end))*24*60*60*1000)
  ),
  yaxis = list(title = "",
               range = c(min_value, max_value),
               showgrid=TRUE),
)

```

Any suggestions?

Thank you

---

<div class="post-metadata">

### Author: ![dsaad](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/dsaad/32/16172_2.png) [@dsaad](https://community.plotly.com/u/dsaad)
#### Post date: [August 29, 2021, 6:20pm UTC](https://community.plotly.com/t/time-series-xaxis-range-bigger-than-data-domain/3889/2 "2021-08-29T18:20:15Z")

</div>

I have a same problem like you. Have you found a solution?

---

<div class="post-metadata">

### Author: ![Roger](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Roger](https://community.plotly.com/u/Roger)
#### Post date: [September 8, 2021, 9:03pm UTC](https://community.plotly.com/t/time-series-xaxis-range-bigger-than-data-domain/3889/3 "2021-09-08T21:03:02Z")

</div>

Unfortunately, I have not.
