You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Restyling a date axis with timestamp data changes axis type to numeric #2144
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]]})
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
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.
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.
vartrace1={name: "trace1",x: [newDate('2020-10-04'),newDate('2021-11-04'),newDate('2023-12-04')],y: [90,40,60],type: 'scatter'};vartrace2={name: "trace2",x: [newDate('2020-10-04'),newDate('2021-11-04'),newDate('2023-12-04')],y: [80,50,40],type: 'scatter'};varlayout={showlegend: true,xaxis: {type: "date"// Explicitly}};Plotly.newPlot('myDiv',[trace1,trace2],layout);setTimeout(function(){// Then I want to leave the legend1. But hide the trace1Plotly.restyle('myDiv',{x: [[null]],y: [[null]]},[0]);// this doesn't work//Plotly.restyle('myDiv', { x: [[null]], y: [[null]] }, [1]); // it works},2000);
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
Activity
[-]Restyling a date axis with timestamp data[/-][+]Restyling a date axis with timestamp data changes axis type to numeric[/+]etpinard commentedon Nov 13, 2017
Side-effect of #1999, thanks for the report.
jdugge commentedon Jan 23, 2018
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.
clearAxisTypesfunction 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 islog, 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.newPlot,relayoutorupdate, theclearAxisTypesflag 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.clearAxisTypesbehaviour when callingrestyle. This doesn't feel right, though, because it doesn't reinstate the old behaviour and because therestylefunction doesn't take any parameters that could be used for this.etpinard commentedon Jan 29, 2018
I think the cleanest way to fix this would be to wait for
ax.autotypeproposed in #2234But 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.
s31tz commentedon Jul 2, 2020
I want to update timeseries data and observe the same problem in v1.54.5. Is there a workaround?
s31tz commentedon Jul 3, 2020
I found a workaround: deleteTraces() + addTraces() instead of restyle(). Downside: The trace must be completely defined.
nikita-zamaraev-loginom commentedon Sep 13, 2021
When clearing the data of the first trace, the display breaks. codepen.io#Plotly.js axis.type discard error
js source code
gvwilson commentedon Jun 10, 2024
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
bparsons5 commentedon Sep 17, 2024
Unfortunately, I am still getting this exact issue. plotly.js v2.35.2.