Plots -- xlims with x axis given by dates?

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?

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

5 Likes

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

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

1 Like

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:

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”.

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

Interesting chart!

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:

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… I did a screen capture, and then used WebPlotDigitizer to convert the plot to numerical data.]