How to make scatter plot with trendline and stats in python

  Рет қаралды 5,361

Karina Adcock

Karina Adcock

Күн бұрын

Get a chart with a linear regression line of best fit and the equation of the line, the r-squared value and the p-value.
---------------------------------------------------------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
x = np.array([2,4,5,7,10])
y = np.array([1,5,4,8,11])
plt.scatter(x,y)
slope, intercept, rvalue, pvalue, stderr = stats.linregress(x,y)
plt.plot(x,slope*x+intercept)
plt.annotate("y=%.3fx+%.3f
R$^2$=%.3f
p=%.3f"%(slope,intercept,rvalue**2,pvalue),xy=(0.15,0.7),xycoords='figure fraction')
plt.show()

Пікірлер: 4
How to make subplots using matplotlib in python
4:09
Karina Adcock
Рет қаралды 844
Curve Fitting in Python (2022)
24:50
Mr. P Solver
Рет қаралды 95 М.
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 13 МЛН
From Small To Giant Pop Corn #katebrush #funny #shorts
00:17
Kate Brush
Рет қаралды 72 МЛН
SHAPALAQ 6 серия / 3 часть #aminkavitaminka #aminak #aminokka #расулшоу
00:59
Аминка Витаминка
Рет қаралды 2,4 МЛН
How to: Import, Plot, Fit, and Integrate Data in Python
24:11
Scatter Plot using Plotly | Python | Data Visualization | Plotly
17:03
How To Plot a Graph of Slope Intercept Form in Python (y=mx+b)
7:09
Try To Be USEFUL
Рет қаралды 4,1 М.
Derivatives In PYTHON (Symbolic AND Numeric)
17:37
Mr. P Solver
Рет қаралды 49 М.
Non-Linear CURVE FITTING using PYTHON
11:37
Phys Whiz
Рет қаралды 77 М.
How to implement Linear Regression from scratch with Python
17:03
Correlation and Regression Analysis: Learn Everything With Examples
9:50
LEARN & APPLY : Lean and Six Sigma
Рет қаралды 1,5 МЛН
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 13 МЛН