Scatter plots in Pandas/Pyplot: How to plot by category

前端 未结 8 925
孤城傲影
孤城傲影 2020-11-22 10:53

I am trying to make a simple scatter plot in pyplot using a Pandas DataFrame object, but want an efficient way of plotting two variables but have the symbols dictated by a t

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 11:04

    It's rather hacky, but you could use one1 as a Float64Index to do everything in one go:

    df.set_index('one').sort_index().groupby('key1')['two'].plot(style='--o', legend=True)
    

    Note that as of 0.20.3, sorting the index is necessary, and the legend is a bit wonky.

提交回复
热议问题