Plotly.js: Handling empty data for Heatmap

Created on 11 Apr 2017  路  4Comments  路  Source: plotly/plotly.js

Hello,
I am trying to handle empty data like " z: [["",""], ["",""]] ".
My expectation is even though there is no subplot to be displayed, I want to display specified time for ticks. So, my script is like following.

var d1= new Date(1491857370000);  
var d2= new Date(1491857371000);  
var d3= new Date(1491857372000);

var data = [
  {x:[d1,d3],
   z: [["",""], ["",""]],
    type: 'heatmap'
  }
];

var layout={
xaxis:{
 tickmode:"linear",
 tick0 : d1, 
 dtick:1000
}
}; 

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

And tick display is according to attached picture.
I've tried with other tickmode like array and auto.
But they all start from date "2000".

So, is there any way to display ticks according to my expectation? (I attached capture for my expected tick display)?
Thanks in advanced

ticks
expectedtick png

bug

All 4 comments

Hi @htetmyomyint - thanks for the report. There are a few things going on here:

  • When we find a trace that has no displayable data in it, we don't display that trace, so in this case we don't have any basis to determine the x and y ranges (so the range falls back to the default with a span of one year, and we draw 5000 ticks at 1 sec intervals before we give up). I can see an argument that heatmaps and contour maps with no z data but recognizable x and y we could at least use the trace to inform axis autoranging... that's a feature we could consider but it's not present now. Unless and until we do that, you can explicitly specify xaxis.range, then turn on xaxis.autorange as soon as some actual data comes in.
  • Although js Date objects are officially supported, we strongly suggest using date strings 'YYYY-MM-DD HH:MM:SS.ssss' or some truncation of that instead. They are more meaningful in a portable (ie JSON) context, particularly as we do not yet have timezone support, and moreover it looks like we may have a bug still in how we interpret js Date objects. I'll mark this as a bug to remind us to investigate that further, but in the meantime I'd encourage you to use the string form.

Hi, any ideas for making this work with categorical x and y axes?
Here's an example showing the setup and invisible plot. I think ideally this would show x and y axis ticks. I tried specifying ranges for x and y axes but that didn't seem to do anything. I'd appreciate any insight or suggestions!

@anfreita I ran into this recently, and found a workaround with categoryorder and categoryarray (see here). You'll probably also want to tweak the axis ranges to more closely match the autorange results.

Phenomenal! Thanks @justin-sleep

Was this page helpful?
0 / 5 - 0 ratings