问题
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:
You could just use string formatting :
plt.plot(x, y, linestyle='solid', color='k', label="Fitting line with $R^{{2}} = {}".format(r_squared))
来源:https://stackoverflow.com/questions/41674696/inserting-a-previously-calculated-value-in-a-legend-in-matplotlib