plotly/plotly.js · warning

Array attribute <refAttr> has fewer entries than expected, e

Error message

Array attribute <refAttr> has fewer entries than expected, extending with default value

What it means

Companion to the truncation warning: when an axis array reference attribute has FEWER entries than expectedLen, plotly.js warns and pads the array with the default value (dflt) until it matches the expected length. The attribute still works, but the padding is implicit and the missing entries use defaults rather than your intent.

Source

Thrown at src/plots/cartesian/axes.js:178

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;
};

/*
 * Get the type of an axis reference. This can be 'range', 'domain', or 'paper'.
 * This assumes ar is a valid axis reference and returns 'range' if it doesn't
 * match the patterns for 'paper' or 'domain'.
 *

View on GitHub (pinned to 1d090e0b5f)

Solutions

  1. Provide one explicit entry per expected axis/domain in the array.
  2. If default behavior for missing axes is fine, pad the array yourself with the documented default value for clarity.
  3. Verify how many axes your subplot grid produces (including 'xN domain' pseudo-axes) and size the array accordingly.

Example fix

// before
layout.xaxis.arrayref = ['x']; // grid has 2 axes
// after
layout.xaxis.arrayref = ['x', 'x2'];
Defensive patterns

Strategy: validation

Validate before calling

function requireFullAxisRefArray(arr, expectedLen, dflt) {
  if (!Array.isArray(arr)) throw new TypeError('expected an array');
  if (arr.length < expectedLen) {
    console.warn(`padding axis ref array from ${arr.length} to ${expectedLen}`);
    return arr.concat(Array(expectedLen - arr.length).fill(dflt));
  }
  return arr;
}

Type guard

const isCompleteArray = (arr, n) => Array.isArray(arr) && arr.length >= n;

Prevention

When it happens

Trigger: Supplying an array-valued axis reference attribute with fewer elements than the number of axes/domains it is applied to, e.g. one entry where the grid has several axes or domains.

Common situations: Removing axes from a config but forgetting to shorten/keep arrays consistent; hand-written layouts with partial arrays; programmatically built arrays that skipped axes without data.

Related errors


AI-assisted analysis of plotly/plotly.js@1d090e0b5f (2026-09-02). Data as JSON: /api/errors/f815e41c2714d995. Report an issue: GitHub.