0

I have data in a pandas dataframe that I need to plot as a scatter plot, but I need to both colormap the points to a third column (day) and vary the marker style based on a fourth column (set). My data is of the form:

import pandas as pd
results = pd.DataFrame([[85,72,1,630], [67,50,1,700], [90,43,2,630], [79,53,2,700]], 
                       columns = ['x', 'y', 'day', 'set'])

but I have many more values for 'day' and 'set' in the actual dataframe.

I tried copying the example given in the pandas.Dataframe.plot.scatter documentation to achieve the colormap, but I got the ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not ['1', '1', '2', '2']. I think I should be able to write a dictionary that indicates a marker style for each set value, but I don't know how to call this in df.plot.scatter().

A Roush
  • 1
  • 1
  • I think [this](https://stackoverflow.com/a/70191707/10452700) and [this](https://stackoverflow.com/a/40961466/10452700) threads would be a good starting point. The `marker` argument used for scatter plot via `df.plot.scatter()` is not as easily used iteratively as the `color` or `c` argument [ref](https://stackoverflow.com/a/35142701/10452700). So [this answer](https://stackoverflow.com/a/26490966/10452700) should be close to your solution. color can be mapped and plot via `color_dict = {1:'red', 2:'green'}` but mapping markers like `marker_dict = {630:'o', 700:'^'}` is not easy to adapt. – Mario Feb 15 '23 at 04:12
  • 2
    **without** `markers` dict/list, I would easily suggest `df.plot.scatter(x='x',y='y',c=[ color_dict[i] for i in df['day'] ])` or `sns.scatterplot(data = df, x = 'x', y = 'y',c = [ color_dict[i] for i in df['day'] ])` – Mario Feb 15 '23 at 04:16

0 Answers0