0

I have three lists of equal length. List A contains a name/category, list B a date and list C a value. e.g.:

A=['Berlin', 'Berlin', 'Berlin', 'Rome','Rome', 'Rome', 'Paris', 'Paris', 'Paris', 'Paris']
B=[1,2,3,1,2,3,1,2,3,4]
C=[34,32,33,23,21,22,17,18,17,19]

Now I'd like to make a scatter plot of C over B, grouped by A. So in this example three data sets (one for each city) in one scatter plot (ideally with different color and label each). I have tried finding ways how to do this with matplotlib.pyplot, but haven't found an appropriate answer in my search unfortunately. Can someone please advise me which way to go?

  • 1
    looks promising, thanks, I'll try that! I tried finding a way without using pandas/dataframes, but maybe this is easier. – justmyluck Feb 11 '22 at 15:27
  • There is, of course, a base matplotlib solution like `unique_A = list(dict.fromkeys(A)); plt.scatter(B, C, c=[unique_A.index(item)/(len(unique_A)-1) for item in A])` but then you would have to generate a legend from scratch. – Mr. T Feb 11 '22 at 17:15

0 Answers0