0

I have a dataframe like this:

 batsman       balls    runs     strike_rate    6's     4's     Team    Highest_score
A Ashish Reddy  196     280     142.857143      16      15      DC      10
A Ashish Reddy  196     280     142.857143      16      15      SRH     36
A Chandila      7       4       57.142857       0       0       RR      4
A Chopra        75      53      70.666667       7       0       KKR     24...

What I am trying to do is plot a scatter plot so that I can compare 2 batsman. So I wrote a funtion:

batsman1='MS Dhoni'
batsman2='V Kohli'
def batsman_comparator():
    sns.FacetGrid(balls,hue='Team',size=8).map(mlt.scatter, "runs", "strike_rate", alpha=0.5).add_legend()
    bats1=balls[balls['batsman']==batsman1]
    bats2=balls[balls['batsman']==batsman2]
    mlt.scatter(bats1["runs"],bats1["strike_rate"],s=50,c='#55ff33')
    mlt.text(bats1["runs"],bats1["strike_rate"],batsman1,
        fontsize=10, weight='bold', color='#f46d43')
    mlt.scatter(bats2["runs"],bats2["strike_rate"],s=50,c='#f73545')
    mlt.text(bats2["runs"],bats2["strike_rate"], batsman2, 
        fontsize=10, weight='bold', color='#ff58fd')
    mlt.show()
batsman_comparator()    

Okay so by using the function I was able to get the plots properly. But as I added the mlt.text() inorder to show the names of the batsman on the particular points, I get a this error:

TypeError: cannot convert the series to <class 'float'>

Now on removing the mlt.text() the function is working fine. How do I display the name for the batsman using the mlt.text(). Any other alternative is also fine..

user517696
  • 2,472
  • 7
  • 24
  • 35

1 Answers1

0

You don't appear to be using mlt.text() correctly. See the Matplotlib documentation here. I believe the text() function can only be applied at a single point. I think you might instead be looking for mlt.annotate(). This StackOverflow question might be helpful.

Svit
  • 311
  • 3
  • 7