✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

X-axis "category" type not honored after Plotly.restyle

I’ve been working with a stacked bar chart. For the X-axis, although the values are numbers in ascending order (in increments of two), it is important that no additional values be interpolated in between the values I list explicitly in my data model. For this reason, I set the type of the X-axis to category in the layout object passed to Plotly.newPlot.

This seemed to work just fine, until I added a feature to my app that would result in edits being made to the data model. With this, I update one or more “Y” values, then call Plotly.restyle to update the chart onscreen.

After doing this, I noticed that the appearance of the X-axis had changed, as though Plotly were now treating it as a regular linear numeric axis. I am able to set things right again by following up the restyle call with a call to Plotly.relayout:

Plotly.relayout(chartElt, {"xaxis.type": "category"});

However, it seems odd to me that I should have to do this.

Is this the intended behavior, or have I possibly got something wrong in how I am setting up my data model or calling into the Plotly API?

I have created a simplified version of what I’m doing, which demonstrates the quirk I’ve encountered. Find the Pen here: https://codepen.io/ecrosland/pen/RwoRjdd
(Uncomment line 21 of the JS to bring in the relayout call that sets the X-axis back to being categorical.)