I'm making a basic scatterplot for a school project similar to the one here: How do I assign different dots different colors in a scatter plot made with MatPlotLib?
The only difference is my data is movie revenues by release date. So x-axis is release dates, and y-axis is revenue. I have a third column that indicates if the movie is Chinese or Foreign, and I want to assign red and blue to the scatter points based on that. I used the method in the link to assign Chinese to 'r' and Foreign to 'b'.
However plot_date doesn't seem to to take the same c = colors argument. I get this error:
fig, ax = plt.subplots() colors = [x2['Country and Region'].replace('Foreign','b').replace('China','r')] mpl.pyplot.plot_date(x2['Release date'],x2['Total Box Office (million)'], c = colors) fig.autofmt_xdate()
ValueError: to_rgba: Invalid rgba arg "[0 r 1 b 2 r 3 b 4 r 5 b 6 r 7 r 8 r 9 r 10 b 11 b 12 r 13 b 14 r 15 r 16 b 17 b 18 r 19 b 20 r 21 r 22 b 23 b 24 b Name: Country and Region, dtype: object]" length of rgba sequence should be either 3 or 4
How can I fix this? Is there another plot method I should be using? I am using plot_date because I couldn't get the plot to display with mpl.pyplot.scatter. (The dates are formatted mm/dd/yr and come from an excel sheet. When I try .scatter it says invalid type promotion. pic1.pic2)