Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17477

add text to a legend in python

$
0
0

I am trying to add some text to the legend. It is about the text in the box. Another solution is that the textbox stays beneath the legend and doesn't move when you enlarge the graph.

plt.scatter(stageheight,discharge,color='b',label='measured data')plt.plot(stageheight_hecras,discharge_hecras,'y^',label='modeled with HEC-RAS')plt.plot(stageheight_masked,discharge_predicted,'r-',label='regression line measured data')plt.plot(stageheight_hecras,discharge_predicted_hecras,'g-',label='regression line HEC-RAS')plt.plot(stageheight_masked,upper,'r--',label='15% error measured data')plt.plot(stageheight_masked,lower,'r--')plt.plot(stageheight_hecras,upper_hecras,'g--',label='30% error HEC-RAS')plt.plot(stageheight_hecras,lower_hecras,'g--')plt.fill_between(stageheight_masked,upper,lower,facecolor='red',edgecolor='red',alpha=0.5,label='test')plt.fill_between(stageheight_hecras,upper_hecras,lower_hecras,facecolor='green',alpha=0.5)plt.axhline(y=0.6,xmin=0,xmax=1,color='black',linewidth = 4.0,label='measuring range')plt.text(0.02,0.7,'measured rating curve $Q = 1.37H^2 + 0.34H - 0.007$\nmodeled ratign curve $Q = 2.71H^2 - 2.20H + 0.98$',bbox=dict(facecolor='none',edgecolor='black',boxstyle='square'))plt.title('Rating curve Catsop')plt.ylabel('discharge')plt.ylim(0,2.5)plt.xlim(0,1.2)plt.xlabel('stageheight[m]')plt.legend(loc='upper left', title='Legend')plt.grid(True)plt.show()

This is the graph I have now:

this is the graph i have now


Viewing all articles
Browse latest Browse all 17477

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>