Inserting a previously calculated value in a legen

2020-04-24 17:13发布

This should be simple, but I haven't found it: I have a value (the coefficient R squared) previously calculated and I want to insert it in a legend in matplotlib. If the value calculated is r_squared, this is not working:

plt.plot(x, y, linestyle='solid', color='k', label=r'Fitting line with $R^{2} = $, r_squared')

It just don't read the value.

Thanks.

1条回答
\"骚年 ilove
2楼-- · 2020-04-24 17:41

You could just use string formatting :

plt.plot(x, y, linestyle='solid', color='k', label="Fitting line with $R^{{2}} = {}".format(r_squared))
查看更多
登录 后发表回答