plotly/plotly.js · warning
Array attribute <refAttr> has more entries than expected, tr
Error message
Array attribute <refAttr> has more entries than expected, truncating to <expectedLen>
What it means
When normalizing an axis array attribute referenced across subplot domains (e.g. axis anchors or similar ref arrays evaluated per domain), plotly.js expects axRef to have exactly one entry per expected slot (expectedLen, derived from the axis list and extra options). If the array is longer, it logs this warning and truncates it to expectedLen, silently dropping extra entries.
Source
Thrown at src/plots/cartesian/axes.js:174
* extraOption if there is no axis)
* extraOption: aside from existing axes with this letter, what non-axis value is allowed?
* Only required if it's different from `dflt`
*/
axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraOption, expectedLen) {
const axLetter = attr.charAt(attr.length - 1);
var axlist = gd._fullLayout._subplots[axLetter + 'axis'];
const refAttr = attr + 'ref';
var axRef = containerIn[refAttr];
// Build the axis list, which we use to validate the axis references
if(!dflt) dflt = axlist[0] || (typeof extraOption === 'string' ? extraOption : extraOption[0]);
axlist = axlist.concat(axlist.map(x => x + ' domain'));
axlist = axlist.concat(extraOption ? extraOption : []);
// Handle array length mismatch
if(axRef.length > expectedLen) {
// if the array is longer than the expected length, truncate it
Lib.warn('Array attribute ' + refAttr + ' has more entries than expected, truncating to ' + expectedLen);
axRef = axRef.slice(0, expectedLen);
} else if(axRef.length < expectedLen) {
// if the array is shorter than the expected length, extend using the default value
Lib.warn('Array attribute ' + refAttr + ' has fewer entries than expected, extending with default value');
axRef = axRef.concat(Array(expectedLen - axRef.length).fill(dflt));
}
// Clean all axis references, replace with default if invalid
for(var i = 0; i < axRef.length; i++) {
axRef[i] = axisIds.cleanId(axRef[i], axLetter, true) || axRef[i];
if(!axlist.includes(axRef[i])) axRef[i] = dflt;
}
containerOut[refAttr] = axRef;
return axRef;
};
/*View on GitHub (pinned to 1d090e0b5f)
Solutions
- Trim the array to match the number of expected axes/domains before setting the layout.
- Count the actual axes in your grid and build the array from that count, not from data series count.
- Check the number of warnings to identify which attribute (refAttr) carries the extra entries and remove the surplus values.
Example fix
// before layout.xaxis.arrayref = ['x', 'x2', 'x3']; // grid has only 2 axes // after layout.xaxis.arrayref = ['x', 'x2'];
Defensive patterns
Strategy: validation
Validate before calling
function fitAxisRefArray(arr, expectedLen, dflt) {
if (!Array.isArray(arr)) throw new TypeError('expected an array');
if (arr.length > expectedLen) throw new RangeError(`array has ${arr.length} entries, expected at most ${expectedLen}`);
return arr.slice();
} Type guard
const hasExactOrFewerEntries = (arr, n) => Array.isArray(arr) && arr.length <= n;
Prevention
- Size axis reference arrays from the subplot grid axis count, not data series count.
- Recompute arrays whenever you add/remove subplots.
- Read the warning's refAttr name to find the offending attribute.
- Write one entry per axis including domain pseudo-entries.
When it happens
Trigger: Passing an array-valued axis reference attribute with more elements than there are target axes/domains, e.g. supplying more entries than the number of axes in the subplot grid that the attribute applies to.
Common situations: Copy-pasting a multi-axis config and not trimming the array after removing subplots; generating arrays programmatically with one entry per data series instead of per axis; upgrading to a version that changed the expected length computation.
Related errors
- Array attribute <refAttr> has fewer entries than expected, e
- c2dApply: axArray and valArray must be the same length
- fixedrange was specified as false for axis <axName2> but was
- ignored <axOut._name>.matches: "<axIn.matches>" to avoid an
- ignored <axOut._name>.scaleanchor: "<axIn.scaleanchor>" to a
AI-assisted analysis of plotly/plotly.js@1d090e0b5f (2026-09-02).
Data as JSON: /api/errors/b51a1b17aa244144.
Report an issue: GitHub.