# Plots -- xlims with x axis given by dates?

**URL:** <https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926>\
**Category:** General Usage\
**Created:** [October 7, 2020, 12:20pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926 "2020-10-07T12:20:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 7, 2020, 12:20pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926/1 "2020-10-07T12:20:12Z")

</div>

I’m plotting some data as a function of _date_, e.g., `plot(date_vector, data_vector)`. I produce several plots with different pairs of `date_vector` and `data_vector`. So I’d like to use the same `xlims` in all plots.

Specifying `xlims = (min_date, max_date)` where `min_date` and `max_date` are dates gives an error message.

Is there a way to do this?

---

<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:** [October 7, 2020, 12:22pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926/2 "2020-10-07T12:22:53Z")

</div>

Yes, just do `xlims = Dates.value.([min_date, max_date])`

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 7, 2020, 12:50pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926/3 "2020-10-07T12:50:05Z")

</div>

Thanks! I had to change it to `xlims = Dates.value.((min_date,max_date))`, i.e., `value` instead of `values`.

---

<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:** [October 7, 2020, 1:09pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926/4 "2020-10-07T13:09:40Z")

</div>

Yes apologies, that was a typo! Have fixed it above for posterity

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 7, 2020, 1:27pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926/5 "2020-10-07T13:27:39Z")

</div>

Another Plots question – this was discussed some time ago, but is still an unsolved problem…

When plotting two series in one plot using `twinx()`, the left side `ylabel` shows up fine. However, the right side `ylabel` is only partially showing:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/5/a5af0e9fc3580ffe4387c1e7cd216f87d9f414c6.png)

The right hand side ylabel should be `mask use` (just like the orange label).

If I save the file as svg and open it in Inkscape, the text is there. It is just that `plot` doesn’t show the entire plot, and this carries over when I save it using `savefig`. [Jupyterlab, Windows 10, 64bit.]

Any idea of what is wrong/how to fix it? It is kind of clumsy to have to open the svg-file in Inkscape and expand the “view”.

---

<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:** [October 7, 2020, 2:51pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926/6 "2020-10-07T14:51:27Z")

</div>

Yes this is a known issue, see here including a workaround for now: [https://github.com/JuliaPlots/Plots.jl/issues/2636](https://github.com/JuliaPlots/Plots.jl/issues/2636)

Interesting chart!

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 7, 2020, 3:38pm UTC](https://discourse.julialang.org/t/plots-xlims-with-x-axis-given-by-dates/47926/7 "2020-10-07T15:38:34Z")

</div>

This workaround doesn’t work. I use Jupyterlab in Chromium based MS Edge, so it should work as Chrome.

In the past, if I did:

```julia
plot(...)
savefig(..)

```

in a Jupyter cell, the figure was plotted and saved. However, in the current/latest version of IJulia, If I have any non-plot commands (e.g., savefig) after the last plot command in a cell, the figure is not plotted.

In the past, I could also open the svg-file in a web-browser, and see the complete RHS ylabel. But now, this has been cut out when I open the svg-file in Inkscape, so Inkscape only shows what is shown in IJulia.

[The chart is “stolen” from [COVID-19](https://covid19.healthdata.org/global?view=total-deaths&tab=trend)… I did a screen capture, and then used WebPlotDigitizer to convert the plot to numerical data.]
