简体   繁体   中英

annotate in scatter plot

I have the following code to plot scatter graph in python. I want to label the labels at xy point. but I am getting below error for this code.

import matplotlib.pyplot as plt
friends = [ 70, 65, 72, 63, 71, 64, 60, 64, 67]
minutes = [175, 170, 205, 120, 220, 130, 105, 145, 190]
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
plt.scatter(friends, minutes)
for label,friends_count,min_count in zip(friends,minutes,labels):
    plt.annotate(label,xy=(friends_count,min_count))
plt.title('Daily Minutes vs Friends count')
plt.xlabel=('friends count')
plt.ylabel=('Daily Minutes')
plt.show()

Error: ValueError: could not convert string to float: a

matplotlib.figure.Figure at 0x9279630

Replacing the zip as shown will fix the issue. for label,friends_count,min_count in zip(labels,friends,minutes): plt.annotate(label,xy=(friends_count,min_count))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM