Python matplotlib manipulating to use it in the plot title


Python matplotlib manipulating to use it in the plot title



assume I've the following variable


roundi = theta_result_lasso.round(2)
[ 0. -2.36]



where theta_result_lasso.round are just two values.



The line for my plot title is


ax.set_title(r'Globales Minimum $hat beta$ = {}'.format(roundi), fontsize=20)



producing this:



enter image description here



is there a way to replace the "." after the zero by a "," and descreasing the disance between the two values as it should look like a "vector" ?



It should look like this:


[0, -2.36]



If you Need further informations, I'll provide an example





what is type(roundi)?
– jedwards
Jul 1 at 22:16


type(roundi)





class 'numpy.ndarray'
– Leo96
Jul 1 at 22:18




2 Answers
2



If your array consist of two variables every time, the easiest would be to format your string something like the following


roundi = [0.0,-2.36]
titlestring = 'Globales Minimum $hat beta$ = [{:0.0f}, {:0.2f}]'.format(roundi[0],roundi[1])



The values in roundi are accessed and formatted individually here.
This will result in the following formatting


roundi


'Globales Minimum $\hat x08eta$ = [0, -2.36]'



Use this:


ax.set_title(r'Globales Minimum $hat beta$ = {}'.format(str(roundi) ),
fontsize=20)





This would result in [ 0, -2,36] (two commas)
– jedwards
Jul 1 at 22:38


[ 0, -2,36]






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?