在matplotlib的图例中插入先前计算的值 [英] Inserting a previously calculated value in a legend in matplotlib

查看:67
本文介绍了在matplotlib的图例中插入先前计算的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很简单,但是我还没有找到它:我有一个先前计算出的值(系数R的平方),我想将其插入到matplotlib的图例中.如果计算出的值为r_squared,则该值不起作用:

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')

只是不读取值.

谢谢.

推荐答案

您可以只使用字符串格式:

You could just use string formatting :

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

这篇关于在matplotlib的图例中插入先前计算的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆