Charts with Trendlines

Consider the previous scatter plot example:

scatter_data = [
    {"income": 30_000, "life_expectancy": 65.5},
    {"income": 35_000, "life_expectancy": 62.1},
    {"income": 50_000, "life_expectancy": 66.7},
    {"income": 55_000, "life_expectancy": 71.0},
    {"income": 70_000, "life_expectancy": 72.5},
    {"income": 75_000, "life_expectancy": 77.3},
    {"income": 90_000, "life_expectancy": 82.9},
    {"income": 95_000, "life_expectancy": 80.0},
]

incomes = []
expectancies = []
for item in scatter_data:
    incomes.append(item["income"])
    expectancies.append(item["life_expectancy"])

print(incomes)
print(expectancies)
[30000, 35000, 50000, 55000, 70000, 75000, 90000, 95000]
[65.5, 62.1, 66.7, 71.0, 72.5, 77.3, 82.9, 80.0]
from plotly.express import scatter

fig = scatter(x=incomes, y=expectancies, height=350,
          title="Life Expectancy by Income",
          labels={"x": "Income", "y": "Life Expectancy (years)"},
)
fig.show()

Upon viewing the chart, looks like there may be evidence of a trend.