[Tutor] Matplotlib.pyplot - How to Insert Computed values in Plot Legend

Mark Lawrence breamoreboy at gmail.com
Sat Oct 24 12:20:01 EDT 2020


On 24/10/2020 13:50, Stephen P. Molnar wrote:
> I have written a Python script to plot Linear Regression results using 
> python-3.7.3 with matplotlib-3.3.0 on my Debian Buster platform.
> 
> 
> The script also calculates a number of statistical parameters as well as 
> the slope (b-sub-1) and intercept (b-sub-0) of the regression line. 
> However, there remain several problems for which I have not be able to 
> find a solution, in spite of Google.
> 
> The code for the plot legend at this point is:
> 
> red_patch = mpatches.Patch(label='A = b$_1$*log(IC$_5$$_0$) - b$_0$ 
> \nr$^2$ = ')
> .
> .
> .
> plt.legend(handles=[red_patch], loc='lower right', frameon=False)
> 
> 1. How can I insert formatted values for the slope, intercept i and r-sq 
> in the legend?
> 2. How can I change the blue line in the legend to the same thickness of 
> the regression line?
> 
> I would greatly appreciate assistance in resolving these problems.
> 
> Thanks in advance.
> 

As this isn't core python I suggest that you start here 
https://matplotlib.org/3.3.2/contents.html

Failing that try stackoverflow which has 100s if not 1,000s of 
matplotlib Q and As.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list