# Vspan vertical scale wrong when using dates as x axis

**URL:** <https://discourse.julialang.org/t/vspan-vertical-scale-wrong-when-using-dates-as-x-axis/31904>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 5, 2019, 1:17pm UTC](https://discourse.julialang.org/t/vspan-vertical-scale-wrong-when-using-dates-as-x-axis/31904 "2019-12-05T13:17:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [December 5, 2019, 1:17pm UTC](https://discourse.julialang.org/t/vspan-vertical-scale-wrong-when-using-dates-as-x-axis/31904/1 "2019-12-05T13:17:21Z")

</div>

Hello,  
I am trying to use vspan to highlight specific periods in a plot with dates as x axis. It seems that vspan changes the y axis units to dates also (which is wrong).

MWE :

```julia
# Show vspan problem with date abscissaes
using Plots
using Dates

gr()
#ENV["GKSwstype"]="nul" # from batch / no X11
#ext=".svg"
ext=".png"
sf=true

y=[1.0*i*i for i in 1:10]
@. y= -y + 5.0

# x=[i+0.0 for i in 1:10]
x=[Date(2019,11,i) for i in 1:10]

rx=[x[3],x[5]]
ry=[y[3],y[5]]

p=plot(x,y, label="y", title="Vspan problem with dates")
if sf; savefig(p,"p-plot"*ext); end

p=vspan!(p,rx,label="",alpha=0.2)
if sf; savefig(p,"p-vspan"*ext); end

```

Here is the (incorrect ?) result  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/7/97cfb5878ec2c0ed2ab2581d78bee81ba2a09c61.png)

What can I do to go around this ?  
Thanks in advance,

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 5, 2019, 10:02pm UTC](https://discourse.julialang.org/t/vspan-vertical-scale-wrong-when-using-dates-as-x-axis/31904/2 "2019-12-05T22:02:57Z")

</div>

Maybe file an issue with Plots.jl - I remember having this issue with vline which got fixed a while ago, maybe that fix wasn’t transposed to vspan

---

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [December 12, 2019, 3:38pm UTC](https://discourse.julialang.org/t/vspan-vertical-scale-wrong-when-using-dates-as-x-axis/31904/3 "2019-12-12T15:38:59Z")

</div>

Thank you @nilshg ! You are right, the problem was fixed inside **vline** , while it remains in **vspan** (and **bar**?).  
But this gave me the following go-around : if i do an additional vline!, this fixes the y axis scale ! 🙂

```julia
  p=vline!(p,[rx[1]], label="",alpha=0.0)

```

So, thank you for helping solve my problem.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 12, 2019, 3:39pm UTC](https://discourse.julialang.org/t/vspan-vertical-scale-wrong-when-using-dates-as-x-axis/31904/4 "2019-12-12T15:39:28Z")

</div>

Haha, nice one, glad that worked!
