Skip to content
Advertisement

How to label points in a scatter plot using zip and annotate

I am trying to use the zip and annotate in order to add labels in a vector tlab to a plot made using matplotlib. Instead, whilst trying to add the labels to the plot I get the error

TypeError: unsupported format string passed to list.format

How can I get the points on the plot using this method?

code:

JavaScript

enter image description here

In my original problem, I have the labels in a vector and they are not referencing the coordinates. I know I could perhaps create a counter that loops through the label vector but I’d like to find the most efficient way to write this.

Advertisement

Answer

You could just zip the labels with the xsand ys. However, I am not sure why you create a list of strings and try to format it later. In the following solution you could also create the formatted strings as in your example and then later just use that as a label directly.

JavaScript

Plots this:

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement