Facett by trend + annotate trend line

Does anyone have a way, including workarounds, to

  1. facet by trend (e.g. columns by pos/neg slope or bins of slope value ranges)

  2. apply text label (once) to a scatter series, preferable the trend line itself (potentially angled with the trendline—just want to see how this looks in some contexts)

I really this might be a “stage it in pandas” thing but curious if others have already done things like this and have examples/snippets. thx!

Hi @njcode , welcome to the forums.

I’m having difficulties to imagine what you are trying to do, at least for the first part. The second part should be doable with annotations.

Hi @AIMPED , thanks for your reply. I tinkered with this a bit more in the meantime.

  1. I figured out an MVP for this part. I will try to remember to share if I get around to cleaning up the code. Image attached. Basically I
  • pulled the rsquared value from from px_fit_results()
  • pulled the sign from alpha
  • merged this result into the data for the viz
  • faceted on this new field

Not necessarily something useful in many cases but for the data I was exploring, I wanted to at least try breaking up some of the series by trend. I am not totally happy with this but it’s a start.

  1. This is not quite what I wanted (main intent is to place the annotations procedurally in a neat way, similar to force simulation here (Plot: Slope chart / Observable | Observable) but it’s a start. The rotation is most to make the annotations ‘stick’ to the relevant trendline esp. if placed on the chart area (here they are pushed over like tickmarks…not perfect obviously).

Hi @njcode , I think I would calculate the trend lines with an other python lib and just plot line annotations with text.

Search for Adding Text Labels to Shapes on this page: