Skip to content

Function: getTrendlineResults() ​

ts
function getTrendlineResults(figure): readonly TrendlineResult[];

The OLS fits of a figure built with trendline: 'ols' (plotly.py's px.get_trendline_results(fig)): one result per trendline trace, with the group it was fit on and statsmodels-like results (params, rsquared, bse, pvalues, …). Pass the figure an Express function returned, or the chart it rendered (await hx.scatter(el, …)). The results are kept beside the figure object, not in it, so they do not survive chartToJSON, structuredClone or a copy of the figure (as plotly.py keeps them on the Python figure only); other kinds of trendline, and figures without one, give [].

Parameters ​

ParameterType
figureobject | ExpressFigure

Returns ​

readonly TrendlineResult[]

Example ​

ts
const figure = hx.scatter(tips, { x: 'total_bill', y: 'tip', color: 'sex', trendline: 'ols' });
const [female] = hx.getTrendlineResults(figure);
female.groups; // { sex: 'Female' }
female.fit.params; // [intercept, slope]
female.fit.rsquared;

Released under the MIT License.