Axis year strings being reformatted as numbers and interpolated
See original GitHub issueMaybe I’m just nuts, but I can’t figure this out. When I pass an array of stringified years as data to Plotly, it interpolates the strings as numbers:
http://codepen.io/anon/pen/RrayBx
Note that it shows my years as “2013”, but then interpolates them as “2,013.5”. Ugh.
It seems likely that tickformat
could help me here, but I’ve looked at https://github.com/mbostock/d3/wiki/Formatting#numbers and https://docs.python.org/release/3.1.3/library/string.html#formatspec and none of those options seem to help. They change the value, but nothing fixes it for real.
IF I have multiple years ['2014', '2015'],
then setting tickformat: 'd'
“works”. That feels like a violation of the spirit of what I want, though: a year is not a decimal number, it’s a string. And I’m passing it in as a string, not a decimal number.
And perhaps a related bug: with only one year tickformat: 'd'
doesn’t work either. It hides the label entirely:
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (8 by maintainers)
Top GitHub Comments
@tlrdstd plotly.js considers all numeric strings as numbers (i.e. floating points numbers) throughout the code. The main reason for this is to have a seamless API for folks feeding plotly.js with numeric strings coming from DOM nodes.
In your case, you can tell plotly.js that your data represent strings (or categories in plotly.js lingo) by adding
type: 'category'
in the axis attributes. See http://codepen.io/etpinard/pen/JGKEzQNote that there is currently no way to customize the order of the categories, plotly.js plots them in the order of the input data. We hope to add an ordering axis attribute soon.
@ronyarmon please ask questions of the likes on https://community.plot.ly/c/api/python