# Facett by trend + annotate trend line

**URL:** https://community.plotly.com/t/facett-by-trend-annotate-trend-line/81127
**Category:** 📊 Plotly Python
**Created:** [December 22, 2023, 6:11pm UTC](https://community.plotly.com/t/facett-by-trend-annotate-trend-line/81127 "2023-12-22T18:11:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![njcode](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@njcode](https://community.plotly.com/u/njcode)
#### Post date: [December 22, 2023, 6:11pm UTC](https://community.plotly.com/t/facett-by-trend-annotate-trend-line/81127/1 "2023-12-22T18:11:25Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)
#### Post date: [December 26, 2023, 12:34am UTC](https://community.plotly.com/t/facett-by-trend-annotate-trend-line/81127/2 "2023-12-26T00:34:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![njcode](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@njcode](https://community.plotly.com/u/njcode)
#### Post date: [December 28, 2023, 5:00pm UTC](https://community.plotly.com/t/facett-by-trend-annotate-trend-line/81127/3 "2023-12-28T17:00:13Z")

</div>

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.

 ![Screenshot 2023-12-28 at 11.28.38 AM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/1/b/1bd94735cfb8dabef9ba7956bd40b7528cb97afe.jpeg)

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](https://observablehq.com/@observablehq/plot-slope-chart)) 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).

 ![Screenshot 2023-12-28 at 11.53.59 AM](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/5/1/5187fba03e606f471f8a6e576ccab7de2cba4448.png)

---

<div class="post-metadata">

### Author: ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)
#### Post date: [December 28, 2023, 11:15pm UTC](https://community.plotly.com/t/facett-by-trend-annotate-trend-line/81127/4 "2023-12-28T23:15:11Z")

</div>

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:

> **[Shapes](https://plotly.com/python/shapes/)**
>
> Over 26 examples of Shapes including changing color, size, log axes, and more in Python.
