Skip to content

Restyling a date axis with timestamp data changes axis type to numeric #2144

Description

@jdugge

Starting with Plotly.js 1.31.0, restyling a plot using timestamps instead of date strings turns the axis from a date axis to a numeric axis, even if the original data was in the same format, as can be seen in this codepen. In 1.30.0, this didn't happen.

var trace1 = {
  x: [1509583143188, 1510187943188], 
  y: [1, 2]
};

var data = [ trace1];

var layout = {
  title:'Line and Scatter Plot',
  xaxis: { type: 'date'}
};

Plotly.newPlot('myDiv', data, layout);

// Restyling with the same data turns the axis from date to numeric type
Plotly.restyle('myDiv', {x: [[1509441408043, 1510046208043]], y: [[1, 2]]})

Activity

  1. changed the title [-]Restyling a date axis with timestamp data[/-] [+]Restyling a date axis with timestamp data changes axis type to numeric[/+] on Nov 6, 2017
  2. etpinard commented on Nov 13, 2017

    @etpinard
    Contributor

    Side-effect of #1999, thanks for the report.

  3. jdugge commented on Jan 23, 2018

    @jdugge
    ContributorAuthor

    I'd like to take a shot at fixing this behaviour, but I'm not sure where the best place to tackle this would be.

    • Somehow check in the clearAxisTypes function whether the axis type was set by the user. This seems like a good place to do it, because there's alread a check for whether the axis type is log, from which we infer that the axis type must have been manually set. I don't know how to check whether an axis type was manually set, though.
    • When manually setting an axis when calling newPlot, relayout or update, the clearAxisTypes flag in in the trace attributes could be removed. However, I think the the trace attributes are global to all traces of the same type, so it wouldn't be possible to have the axis type fixed for traces on only one axis.
    • Provide a mechanism for overriding the clearAxisTypes behaviour when calling restyle. This doesn't feel right, though, because it doesn't reinstate the old behaviour and because the restyle function doesn't take any parameters that could be used for this.
  4. etpinard commented on Jan 29, 2018

    @etpinard
    Contributor

    I think the cleanest way to fix this would be to wait for ax.autotype proposed in #2234

    But since this ticket signals a regression, perhaps we should try to make a quick (albeit temporary) fix. In this case, your first bullet point seems like the best solution.

  5. s31tz commented on Jul 2, 2020

    @s31tz

    I want to update timeseries data and observe the same problem in v1.54.5. Is there a workaround?

  6. s31tz commented on Jul 3, 2020

    @s31tz

    I found a workaround: deleteTraces() + addTraces() instead of restyle(). Downside: The trace must be completely defined.

  7. nikita-zamaraev-loginom commented on Sep 13, 2021

    @nikita-zamaraev-loginom

    When clearing the data of the first trace, the display breaks. codepen.io#Plotly.js axis.type discard error

    js source code
    var trace1 = {
        name: "trace1",
        x: [new Date('2020-10-04'), new Date('2021-11-04'), new Date('2023-12-04')],
        y: [90, 40, 60],
        type: 'scatter'
    };
    
    var trace2 = {
        name: "trace2",
        x: [new Date('2020-10-04'), new Date('2021-11-04'), new Date('2023-12-04')],
        y: [80, 50, 40],
        type: 'scatter'
    };
    
    var layout = {
        showlegend: true,
        xaxis: {
            type: "date" // Explicitly
        }
    };
    
    Plotly.newPlot('myDiv', [trace1, trace2], layout);
    
    setTimeout(function () { 
        // Then I want to leave the legend1. But hide the trace1
        Plotly.restyle('myDiv', { x: [[null]], y: [[null]] }, [0]); // this doesn't work
        //Plotly.restyle('myDiv', { x: [[null]], y: [[null]] }, [1]); // it works
    }, 2000);
  8. gvwilson commented on Jun 10, 2024

    @gvwilson
    Contributor

    Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson

  9. bparsons5 commented on Sep 17, 2024

    @bparsons5

    Unfortunately, I am still getting this exact issue. plotly.js v2.35.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions