Skip to content

DateTime in Table causes trouble #333

@tamasgal

Description

@tamasgal

I was plotting some date related datasets today and bumped into the issue with DateTime object. First I thought they are not supported but there the docs mention that both "Date and DateTime types are supported natively" (https://kristofferc.github.io/PGFPlotsX.jl/v1/examples/juliatypes/#Dates)

The example in the docs is

using Dates
dategrid = Date(2000,1,1):Day(1):Date(2000,12,31)
relative_irradiance(d) = (1 + 0.034*cospi(2*Dates.dayofyear(d)/365.25))

@pgf Axis(
    {
        date_coordinates_in = "x",
        x_tick_label_style = "{rotate=90}",
        xlabel = "date",
        ylabel = "relative solar irradiance",
    },
    Plot(
    {
        no_marks
    },
    Table(dategrid, relative_irradiance.(dategrid))))

...and when I replace Date with DateTime, I get the following error:

! Package PGF Math Error: Could not parse input '00:00' as a floating point num
ber, sorry. The unreadable part was near ':00'..

See the PGF Math package documentation for explanation.
Type  H <return>  for immediate help.
 ...      

Looking at the print_tex output reveals that the times appear in an additional column, which explains the error above:

\begin{axis}[date coordinates in={x}, x tick label style={{rotate=90}}, xlabel={date}, ylabel={relative solar irradiance}]
    \addplot[no marks]
        table[row sep={\\}]
        {
            \\
            2000-01-01 00:00  1.0339949694264963  \\
            2000-01-02 00:00  1.0339798791946129  \\
            2000-01-03 00:00  1.033954733769792  \\
            2000-01-04 00:00  1.0339195405929695  \\
            2000-01-05 00:00  1.0338743100783727  \\
...
...
...

I also tried defining column names in the Axis with

			x = "d",
			y = "i",

and then pass Table([:d => dategrid, :i => relative_irradiance.(dategrid)])

but this does not help since the second column has no name 😉

\begin{axis}[date coordinates in={x}, x={d}, y={i}, x tick label style={{rotate=90}}, xlabel={date}, ylabel={relative solar irradiance}]
    \addplot[no marks]
        table[row sep={\\}]
        {
            d  i  \\
            2000-01-01 00:00  1.0339949694264963  \\
            2000-01-02 00:00  1.0339798791946129  \\
            2000-01-03 00:00  1.033954733769792  \\
            2000-01-04 00:00  1.0339195405929695  \\
...
...
...

I also tried to use comma as separator with

	    PGFPlotsX.Plot(
	    {
	        no_marks,
			col_sep="comma"
	    },
	    Table({col_sep="comma"}, [:d => dategrid, :i => relative_irradiance.(dategrid)])))

but somehow it's ignored:

\begin{axis}[date coordinates in={x}, x={d}, y={i}, x tick label style={{rotate=90}}, xlabel={date}, ylabel={relative solar irradiance}]
    \addplot[no marks, col sep={comma}]
        table[row sep={\\}, col sep={comma}]
        {
            d  i  \\
            2000-01-01 00:00  1.0339949694264963  \\
            2000-01-02 00:00  1.0339798791946129  \\
            2000-01-03 00:00  1.033954733769792  \\
            2000-01-04 00:00  1.0339195405929695  \\

Any suggestions? Coordinates does not like dates...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions